MACHINE LEARNING

R² and Adjusted R²

R² measures explained variance — but always increases when you add predictors. Adjusted R² penalises complexity: it only improves if a new predictor earns its place.

1What R² Measures

The coefficient of determination R² answers: how much better is our model than just predicting the mean? It decomposes total variance into explained and unexplained parts.

R² = 1 - SSres / SStot, where SStot = Σ(yi - ŷ)² is total variance and SSres = Σ(yi - ŷi)² is unexplained variance. R² = 0 means the model predicts only the mean. R² = 1 means perfect prediction. R² can be negative for models that perform worse than the mean baseline.

SStot (total)
Variance if you always predict ŷ. Benchmark — how bad the dumbest model is.
SSres (residual)
Unexplained variance after fitting. SSres decreases (never increases) as features are added.
SSreg (explained)
SStot - SSres. How much the model reduces variance vs. the mean. R² = SSreg/SStot.

2The R² Inflation Problem

R² never decreases when predictors are added — even if you add random noise as a feature. This makes it a poor metric for comparing models with different numbers of predictors.

Advertising dataset example: TV alone gives R² = 0.61. Adding radio jumps to R² = 0.897 — radio genuinely helps. Adding newspaper gives R² = 0.897 — almost identical. But R² still increases by a tiny amount. Without a penalty, you might keep newspaper just because it technically raised R².

Why this happens

When a predictor is added, OLS optimises the coefficients to reduce SSres. Even a random predictor has some accidental correlation with the target in the training sample. SSres can only decrease, so R² can only increase. The fix is to penalise the degrees of freedom consumed.

3Adjusted R²

Adjusted R² accounts for the number of predictors d and sample size n. It increases only if the new predictor improves the model more than expected by chance.

R²adj = 1 - (SSres/(n-d-1)) / (SStot/(n-1))  =  1 - (1-R²)(n-1)/(n-d-1). As d increases with n fixed, the penalty (n-d-1) shrinks the denominator, making the fraction larger and R²adj smaller — unless SSres drops enough to compensate.

Advertising results

  • TV only: R² = 0.610, R²adj = 0.608
  • TV + radio: R² = 0.897, R²adj = 0.896
  • TV + radio + newspaper: R² = 0.897, R²adj = 0.895

Adding newspaper raised R² but lowered adjusted R² — correctly identifying it as useless.

Limitations of both

  • Both measure fit on training data — not out-of-sample performance
  • Neither detects overfitting caused by nonlinear effects
  • For model selection, prefer cross-validated RMSE or AIC/BIC
  • R² < 0 is valid — it means the model is worse than the mean

4Other Regression Metrics

R² is useful for communicating model quality to non-technical audiences, but practitioners also look at error-scale metrics.

MSE / RMSE
Mean squared / root mean squared error. RMSE is in the same units as y — directly interpretable. Sensitive to large outliers because errors are squared.
MAE
Mean absolute error. More robust to outliers than MSE because it doesn't square residuals. Trade-off: MAE is not differentiable at zero, which can complicate gradient-based fitting.
Relationship
R² = 1 - MSE/Var(y). So R² is a normalised MSE. A high-variance target can have low MSE and still yield a mediocre R².

Related

R² and Adjusted R² — computed from scratch with numpy

Recall check

0 of …

Say the answer out loud before revealing — recalling is what makes it stick. ➜ Next: Elastic Net

  1. What do SS_res and SS_tot represent in the R² formula?

  2. Why does R² always increase (or stay flat) when features are added?

  3. How does Adjusted R² fix the R² inflation problem?

  4. When would you prefer RMSE over R² for model evaluation?