← chapter

Judging a regressor

Six ways to squeeze predictions-vs-truth into one number: MSE, RMSE, MAE, R², adjusted R², MAPE.

They are not interchangeable. Different units, different things rewarded, one of them lies when an outlier shows up.

The running question: what unit is this number in?

The units, up front

The picture every metric summarizes

Predicted vs actual on the held-out California blocks; y = x is a perfect model. The vertical gap to the line is each prediction's error.

The math

MSE=1ni=1n(yiy^i)2,RMSE=MSE\text{MSE} = \frac{1}{n} \sum_{i=1}^{n} \left( y_i - \hat{y}_i \right)^2, \qquad \text{RMSE} = \sqrt{\text{MSE}} MAE=1ni=1nyiy^i\text{MAE} = \frac{1}{n} \sum_{i=1}^{n} \left| y_i - \hat{y}_i \right| R2=1SSresSStot=1(yiy^i)2(yiyˉ)2R^2 = 1 - \frac{\text{SS}_{\text{res}}}{\text{SS}_{\text{tot}}} = 1 - \frac{\sum (y_i - \hat{y}_i)^2}{\sum (y_i - \bar{y})^2} MAPE=100ni=1nyiy^iyi\text{MAPE} = \frac{100}{n} \sum_{i=1}^{n} \left| \frac{y_i - \hat{y}_i}{y_i} \right|

The outlier demo

Drag one point out; predictions fixed. MSE and RMSE explode, MAE barely moves.

Residual 0 → 12 units: MSE 0.17 → 7.72 units² (45×), RMSE 0.42 → 2.78 units (~7×), MAE 0.35 → 0.95 units (<3×).

The model's real scores

Every scratch metric matches sklearn.metrics to the last decimal.

Takeaways