Mean squared error tells you how large the errors are, but not whether they are large relative to the spread of the target. A regressor that misses by 5 units is excellent when the target ranges over 1000 and poor when it ranges over 6. The R-squared score fixes that by comparing the model's squared error against the error of the simplest possible model, one that always predicts the mean of the target.
Implement r2_score(y_true, y_pred), which returns 1 - SS_res / SS_tot.
y_true and y_pred must have the same shape, otherwise raise ValueError.y_true is constant, SS_tot is zero and the score is undefined: raise ValueError.1. Predicting the mean scores 0. Worse predictions score below 0.Open one at a time. Each gives away a little more than the last.
SS_tot is the sum of squared differences from the mean of y_true. SS_res is the sum of squared differences between y_true and y_pred.
Check for a constant target with np.all(y_true == y_true[0]) before dividing, so the error is raised for real and not from a division warning.
No results yet
Run your code to check it against the examples, or submit to run every test.