matrics_calculator.r2
Functions
|
Calculates r-squared using linear regression. |
Module Contents
- matrics_calculator.r2.r2(y_pred, y_true)[source]
Calculates r-squared using linear regression.
Computes the r-squared value (coefficient of determination) using the provided y_pred list and y_true list.
- Parameters:
y_pred (list) – y_pred values to be used in calculating r-sqaured value.
y_true (list) – y_true values to be used in calculating r-sqaured value.
- 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.
- Return type:
float
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