The R² score (coefficient of determination) measures what fraction of the target's total variance a regression model successfully explains — unlike MSE/MAE/RMSE, it's on a fixed, comparable scale rather than dependent on the target's raw units.
Formula
\(SS_{res}\) (residual sum of squares) is exactly the numerator behind MSE — the model's actual error. \(SS_{tot}\) (total sum of squares) is how much the target varies from its own mean — the error a "predict the mean for everyone" baseline would produce. R² compares the model's error against that naive baseline.
Worked Example
Using the same regression example: \(y=[52,58,62,68,75]\), \(\bar{y}=63\), \(SS_{res}=2.4\) (5 × MSE of 0.48).
from sklearn.metrics import r2_score
y_true = [52, 58, 62, 68, 75]
y_pred = [51.8, 57.4, 63.0, 68.6, 74.2]
print(r2_score(y_true, y_pred)) # 0.9924
Reading R² Values
| R² Value | Meaning |
|---|---|
| 1.0 | Perfect predictions — model explains 100% of the target's variance |
| 0.0 | No better than always predicting the mean |
| Negative | Worse than always predicting the mean — a genuinely bad model |
R² can go negative — a common source of confusion, since it superficially resembles a percentage. A negative R² means the model's actual predictions are worse than the naive "just guess the average every time" baseline.
Why R² Alone Isn't Always Enough
A high R² doesn't guarantee good predictions in absolute terms — it only measures relative improvement over the mean-baseline. A model could have R²=0.9 while still being off by a business-unacceptable amount on individual predictions, especially if the target has huge natural variance to begin with. Always pair R² with an absolute-error metric like RMSE or MAE for a complete picture.
Adjusted R² — Correcting for Feature Count
\(p\) is the number of features. Plain R² can only increase (or stay flat) as more features are added, even useless ones — Adjusted R² penalizes this, decreasing if a new feature doesn't genuinely improve the fit beyond what chance alone would predict.
Practical Use Cases
- Communicating "how much of the outcome does this model actually explain" in a scale-independent, easily comparable way
- Comparing models across different datasets or targets, where raw MSE/RMSE values aren't directly comparable
Common Mistakes
- Treating R² as a percentage of "accuracy" the way it's sometimes informally described — it specifically measures variance explained, not correctness in the way classification accuracy does.
- Comparing plain R² across models with different numbers of features without switching to Adjusted R².
- Reporting a suspiciously perfect R² (like 0.9924 here, or higher) without checking for data leakage on real-world data.
Interview Relevance
Q: "What does a negative R² mean, and how is that possible?" It means the model's predictions are worse, on average, than simply always predicting the target's mean value — R² isn't bounded below by 0 the way it might intuitively seem; a poorly fit or badly overfit model evaluated on new data can genuinely underperform this trivial baseline.
Practice Question
A model has \(SS_{res}=50\) and \(SS_{tot}=40\). Compute R² and interpret what this unusual result means about the model's quality.