Code QuizIntermediate R-squared Interpretation
Understanding what a negative R-squared means for model quality.
Codepython
from sklearn.metrics import r2_score
y_true = [3.0, 5.0, 7.0, 9.0]
y_pred = [9.0, 7.0, 5.0, 3.0] # predictions trend opposite
r2 = r2_score(y_true, y_pred)
# Assume r2 is always between 0 and 1, so clamp low scores to 0
if r2 < 0:
r2 = 0.0
print(r2)What is the flawed assumption in this code?