matrics_calculator.r2 ===================== .. py:module:: matrics_calculator.r2 Functions --------- .. autoapisummary:: matrics_calculator.r2.r2 Module Contents --------------- .. py:function:: r2(y_pred, y_true) Calculates r-squared using linear regression. Computes the r-squared value (coefficient of determination) using the provided y_pred list and y_true list. :param y_pred: y_pred values to be used in calculating r-sqaured value. :type y_pred: list :param y_true: y_true values to be used in calculating r-sqaured value. :type y_true: list :returns: r-sqaured value which is <= 1. 1 is the best score and a score below 0 is worse than using the mean of the target as predictions. :rtype: float .. rubric:: Examples >>> data = { >>> 'math_test': [80, 85, 90, 95], >>> 'science_test': [78, 82, 88, 92], >>> 'final_grade': [84, 87, 91, 94], >>> 'absences': [3, 0, 1, 30] >>> } >>> r2(data['math_test'],data['final_grade']) 0.997 >>> r2(data['math_test'],data['absences']) 0.541