Regression Metrics
Regression metrics such as MSE, MAE, and R-squared quantify how far continuous predictions fall from the truth.
Measuring continuous error
For regression, error is the numeric gap between predictions and targets. Different metrics summarize these residuals differently, and each answers a different question, so reporting more than one gives a fuller picture.
The common metrics
- MSE (mean squared error): averages squared residuals; punishes large errors heavily, in squared units.
- RMSE: the square root of MSE, back in the target's units, easier to interpret.
- MAE (mean absolute error): averages absolute residuals; robust to outliers, in the target's units.
- MAPE (mean absolute percentage error): scale-free relative error, but unstable near zero targets.
- R-squared: fraction of variance explained, from 1 (perfect) down through 0 (no better than the mean) to negative.
MSE versus MAE
Because MSE squares residuals, a few large errors dominate it, so minimizing MSE fits the conditional mean and is sensitive to outliers. MAE weights all errors linearly, fits the conditional median, and resists outliers. Choose based on whether large errors are disproportionately costly (MSE) or should be treated proportionally (MAE).
from sklearn.metrics import mean_squared_error, mean_absolute_error, r2_score
rmse = mean_squared_error(y_true, y_pred, squared=False)
mae = mean_absolute_error(y_true, y_pred)
r2 = r2_score(y_true, y_pred)
Reading R-squared honestly
R-squared compares your model to a baseline that always predicts the mean. It never decreases when you add features, so adjusted R-squared penalizes extra features to keep the comparison fair. A high R-squared on training data means little; report metrics on a held-out test set. Match the reporting metric to the loss the model optimized where possible.