Regression Metrics
Learn how to measure how good a numeric prediction really is — MAE, MSE, RMSE, R², MAPE, and the residual plots that reveal what the numbers hide.
Before you fit a single regression model, you need an answer to a deceptively simple question: what does "good" mean when you're predicting a number? A classifier is right or wrong; a regression model is off by some amount, and how you summarize those amounts changes which model looks best. In this lesson you'll meet the standard regression metrics, learn where each one shines or lies, and use residual plots to see what a single score can't tell you.
It all starts with residuals
Suppose a model predicts house prices. For each house we have the true price
y and the prediction ŷ. The residual is the gap between them:
residual = y − ŷ
A positive residual means the model predicted too low; negative means too high. Every regression metric is just a different way of squashing a list of residuals into a single number — and each way of squashing makes a different trade-off.
MAE, MSE, and RMSE
The three workhorses:
- Mean Absolute Error (MAE) — average of the absolute residuals. "On average, we're off by this much." Same units as the target.
- Mean Squared Error (MSE) — average of the squared residuals. Punishes big misses much harder, but the units are squared (dollars² — awkward).
- Root Mean Squared Error (RMSE) — the square root of MSE. Back in the target's units, but still outlier-sensitive because the squaring happened first.
The key behavioral difference is outlier sensitivity. Watch what a single terrible prediction does to each metric:
One bad prediction out of eight barely moved the MAE (each point contributes linearly), but MSE exploded and RMSE tripled — the squared 20-unit miss dominates everything. Neither behavior is "correct":
- If big misses are disproportionately costly in your problem (a 20% error in a drug dose is not 2× as bad as a 10% error), RMSE's sensitivity is a feature.
- If your data contains a few noisy, unrepresentative extremes you don't want dominating model selection, MAE is the more robust summary.
R²: better than guessing the mean?
MAE and RMSE are in the target's units, which is great for stakeholders but
hard to compare across problems. R² (the coefficient of determination)
fixes that by comparing your model against the dumbest possible baseline:
always predicting the mean of y.
- R² = 1 — perfect predictions, zero error.
- R² = 0 — your model is exactly as good as predicting the mean.
- R² negative — your model is worse than predicting the mean. Yes, this happens, and it's a loud alarm bell.
That last score is far below zero: the model's errors are bigger than the spread of the data itself. When you see negative R² on a test set, the model learned something that actively misleads it — often a sign of leakage, a bug, or severe overfitting.
R² is the default score in scikit-learn
Calling .score(X, y) on any scikit-learn regressor returns R². When you read
"score = 0.87" in regression code, it almost always means R².
MAPE: intuitive, with a fatal flaw
Mean Absolute Percentage Error reports the average relative error — "off
by 12% on average" — which non-technical audiences love. But it divides by
the true value, so it breaks when y is zero or near zero:
A prediction that missed by one unit blew the MAPE up to astronomical levels, because the miss was divided by 0.001. Avoid MAPE when the target can be zero or close to it (demand forecasting with zero-sale days is the classic trap).
Which metric should you report?
| Situation | Reach for |
|---|---|
| You want an error in the target's units, robust to outliers | MAE |
| Big misses are disproportionately costly | RMSE |
| You're optimizing / comparing models mathematically | MSE (smooth, differentiable) |
| You need a unit-free "how much better than baseline" score | R² |
| A relative "% off" story for stakeholders (targets far from 0) | MAPE |
In practice, report two: one absolute metric (MAE or RMSE) plus R². They answer different questions — "how far off are we?" and "how much of the variation do we explain?"
Residual plots: seeing what the score hides
A single number can't tell you where the model fails. A residual plot — predictions on the x-axis, residuals on the y-axis — can. For a healthy model the residuals look like a structureless, symmetric band around zero. Patterns mean trouble:
- A curve or U-shape — the model is missing a nonlinear relationship.
- A funnel (spread grows with prediction) — heteroscedasticity; errors
grow with the target, often fixed by transforming
y(a later lesson). - Train residuals tiny, test residuals huge — overfitting.
Both panels show a roughly symmetric cloud around zero with similar spread — no obvious curvature, no funnel, and train/test look alike. That's the visual signature of a model that is honest, if not spectacular. Get in the habit of looking at this plot every time you fit a regressor; it catches problems that MAE and R² silently average away.
Check your understanding
Q1.Your predictions are mostly accurate, but one sample is wildly off. Which metric changes the most?
Q2.A model scores R² = −0.4 on the test set. What does that mean?
Q3.Why is MAPE risky for a demand-forecasting problem where some days have zero sales?
Q4.A residual plot shows the spread of residuals growing steadily as predictions increase. What is this pattern called?
Q5.You must report one error metric in the same units as house prices, and the dataset has a few extreme luxury sales you consider noise. Best choice?
Exercise: Judge two models by more than one number
Load load_diabetes, split into train/test, and fit a LinearRegression.
Call its test predictions Model A. Create Model B by copying Model A's
predictions and adding 300 to a single one (simulating one terrible miss).
Compute MAE, RMSE, and R² for both. Which metrics barely notice the corruption,
and which ones panic? Does the ranking of "how bad is Model B" depend on the
metric you choose?
Now that you can measure what "good" means, it's time to earn a score of your own — next: fit your first model with linear regression and gradient descent.