R-squared Score
Easy
~15 min
code completion
R² (Coefficient of Determination)
MSE tells you how large the errors are, but not how well you're doing relative to a baseline. R² answers: "How much better is my model than just predicting the mean?"
where:
Interpretation:
Your task:
Implement r_squared(y_true, y_pred).
Example Tests
Perfect predictions: R2 = 1.0
Input: {"y_pred":[1,2,3,4,5],"y_true":[1,2,3,4,5]}
Expected: 1
Predicting the mean: R2 = 0.0
Input: {"y_pred":[6,6,6,6,6],"y_true":[2,4,6,8,10]}
Expected: 0
Good but not perfect predictions
Input: {"y_pred":[1.5,2,2.5],"y_true":[1,2,3]}
Expected: 0.75