Exercises — Regression metrics (MAE, MSE, RMSE, MAPE)
We keep one small dataset around so you can feel the metrics on the same numbers. Call it Dataset R (rent in $1000s/month):
| Sample | Actual | Predicted |
|---|---|---|
| 1 | 2.5 | 2.8 |
| 2 | 1.8 | 1.6 |
| 3 | 3.2 | 3.9 |
| 4 | 2.1 | 2.0 |
Recall the three building blocks from the parent note, in plain words:
- = the true value (what actually happened).
- = the predicted value (what the model guessed). The little hat "^" is just a mark meaning "this is an estimate, not the real thing."
- = the residual: how far the guess missed. Positive means the model guessed too low; negative means it guessed too high.
- = the number of samples (how many rows are in the dataset). For Dataset R, . Every formula below that starts with is just saying "add everything up, then divide by how many there are" — i.e. take an average.

The figure above shows Dataset R as a number line per sample: the true value is a chalk-blue dot, the prediction a pink dot, and the residual is the segment between them. MAE cares about the length of those segments; MSE cares about the length squared (so a segment twice as long counts four times as much).
Level 1 — Recognition
Can you read a formula and apply it directly?
Exercise 1.1 (L1)
Compute the residual and the absolute error for every sample in Dataset R.
Recall Solution
. We subtract the prediction from the truth, keeping the sign, then take the size.
| 1 | |||
| 2 | |||
| 3 | |||
| 4 |
Samples 1 and 3 have negative residuals (model guessed too high). Samples 2 and 4 are positive (guessed too low). The absolute value throws the sign away because for MAE we only care how far off, not which direction.
Exercise 1.2 (L1)
Using the absolute errors from 1.1, compute the MAE of Dataset R.
Recall Solution
Here (four samples), so we add the four absolute errors and divide by 4: In real units: on average the model is off by $325/month. (Same units as the target — that is MAE's selling point.)
Exercise 1.3 (L1)
Compute the MSE and then the RMSE of Dataset R.
Recall Solution
Square each residual first, because MSE punishes big misses harder: Again with , average the four squares: Those units are "($1000s)² " — awkward. So take the square root to get back to real dollars:
Level 2 — Application
Can you use the formulas on new data and handle the messy bits?
Exercise 2.1 (L2)
A weather model predicts daily high temperatures (°C). Actuals: . Predictions: . Compute MAE and RMSE.
Recall Solution
Here again. Residuals : Absolute: , so Squares: , sum , Notice RMSE (2.449) > MAE (2.0): the single 4° miss is pulling RMSE up.
Exercise 2.2 (L2)
Compute the MAPE of Dataset R.
Recall Solution
For each sample, percentage error . We divide by the true value so a fixed dollar miss counts more on a cheap apartment.
| 1 | 0.3 | 2.5 | 0.120 | 12.0% |
| 2 | 0.2 | 1.8 | 0.1111 | 11.11% |
| 3 | 0.7 | 3.2 | 0.21875 | 21.875% |
| 4 | 0.1 | 2.1 | 0.04762 | 4.762% |
With : Sample 3 dominates — not because its dollar error is biggest (it is, but) mainly because it's the largest fraction of its own true value.
Exercise 2.3 (L2)
One extra sample arrives with (a free promotional unit), . What happens to MAE, RMSE, and MAPE?
Recall Solution
- MAE / RMSE: perfectly fine. The residual is , , . These just add to the sums.
- MAPE: undefined. The term is — division by zero. A single true-zero blows up the entire average.
This is MAPE's fatal flaw (also flagged in the parent note): never use it when the target can be zero. See Outlier detection for spotting such degenerate points early.
Level 3 — Analysis
Can you compare metrics and explain the differences they expose?
Exercise 3.1 (L3)
Two models are scored on the same 4-point test set. Their residuals are:
- Model A:
- Model B:
Compute MAE and RMSE for each. Which model does each metric prefer, and why?
Recall Solution
With for both models. Model A: Squares , , Model B: Squares , ,
| MAE | RMSE | |
|---|---|---|
| Model A | 1 | 1 |
| Model B | 1 | 2 |
MAE calls them tied. Total error magnitude is identical (4 units spread out either way). RMSE prefers A. Squaring makes B's single big miss () dominate, so RMSE flags B as twice as bad.
The figure below shows this as squared-error bars: Model A's four short bars versus Model B's single towering bar. Equal MAE, wildly unequal MSE.
Interpretation: if one catastrophic error is worse than four small ones for your application, trust RMSE. If all errors are equally tolerable, MAE is the honest score. This is exactly the Model comparison judgment call.

The chart makes the trap visible: both models have identical MAE (), yet Model B's lone bar single-handedly pushes its MSE to 4 and its RMSE to 2. That one bar is the reason RMSE and MAE disagree — the geometric meaning of "squaring amplifies large errors."
Exercise 3.2 (L3)
For any dataset, prove that , and state when they are equal.
Recall Solution
Let , and let be the number of samples. Then (the mean of the ) and (the root of the mean of the squares).
First, what is variance? The variance of the list is the average of the squared distances of each value from their mean : It is a sum of squares divided by ; every term , and a sum of non-negative things divided by a positive is non-negative. So always — that is not an assumption, it is forced by the squares.
Now expand that same variance algebraically (multiply out the square and split the sum): (We used .) Combining the two facts: since , Take square roots (both sides non-negative):
Equality holds exactly when , which forces every , i.e. all the absolute errors are identical (Model A in 3.1: every gave ). The bigger the spread of error sizes, the bigger the gap RMSE MAE.
Exercise 3.3 (L3)
MAPE is often said to "penalize underestimation and overestimation unequally." Show this with numbers: true value . Compare predicting (under) versus (over).
Recall Solution
Both predictions miss by the same absolute amount, . But MAPE divides by the true value in both cases: So with the standard MAPE definition (divide by , the true value), these two are actually equal — 10% each.
The asymmetry the parent note warns about appears when you either (a) divide by the prediction, or (b) compare across different true values, or (c) look at the practical bound: over-prediction error is unbounded (predict for → 900% error), while under-prediction is capped at 100% (best you can under-shoot is → 100%). That structural ceiling on under-prediction vs. no ceiling on over-prediction is the real asymmetry, and it quietly nudges models trained on MAPE toward under-predicting. Fix: sMAPE, which divides by .
Level 4 — Synthesis
Can you combine ideas and design solutions?
Exercise 4.1 (L4)
A sales team forecasts demand for products priced from $5 to $5000. They want a single number to compare forecast quality across products, but some products occasionally have true demand of 0 units. Recommend a metric and justify it against MAE, RMSE, and MAPE.
Recall Solution
Requirements: (1) scale-independent (prices span 3 orders of magnitude), (2) survives .
- MAE / RMSE: fail requirement (1). A $50 error is huge on a $5 product, trivial on a $5000 one — but MAE/RMSE add raw dollars, so the expensive products dominate the average. Not comparable across scales.
- MAPE: satisfies (1) but fails (2) — division by zero on the zero-demand products.
- sMAPE (symmetric MAPE): satisfies both. It divides by , so it is percentage-based and only undefined if both actual and predicted are 0 simultaneously (rare, and defensibly treated as 0% error).
Recommendation: report sMAPE as the headline cross-product number, and keep RMSE per product as a secondary diagnostic so you can still see which individual products carry large raw errors. Pair with Feature scaling thinking: sMAPE is essentially "scale-normalizing the error the way we scale-normalize features."
Exercise 4.2 (L4)
You are training a neural network. During training you need a loss to differentiate; for the final report you need an interpretable score. Which metric(s) go where, and why can't you always use the same one for both?
Recall Solution
Training / optimization: use MSE as the loss. Gradient descent needs a smooth (differentiable-everywhere) function of the predictions. MSE's derivative w.r.t. a prediction is clean: a smooth line through zero. MAE's derivative is with a kink at 0 (the absolute value is not differentiable there), which makes optimization jitter near the minimum. This connects directly to Loss functions in neural networks.
Reporting: use RMSE (or MAE). Squared dollars mean nothing to a stakeholder; RMSE undoes the square so the number is in real units and keeps MSE's outlier sensitivity.
Why not one metric for both? The two roles have conflicting demands: optimization wants smoothness, reporting wants interpretability. MSE wins smoothness but loses units; RMSE wins units but the square root is a needless monotone wrapper during gradient steps (minimizing MSE and RMSE give the same optimum, so you optimize the cheaper MSE and report the readable RMSE).
Level 5 — Mastery
Can you reason about metric behaviour at the edges and design a robust evaluation?
Exercise 5.1 (L5)
A dataset has 100 samples. On 99 of them the residual is exactly ; on the 100th (an outlier), the residual is . Compute MAE and RMSE, and quantify how much the single outlier distorts each. Which metric better reflects "typical" performance?
Recall Solution
Here . MAE: Without the outlier, MAE would be . So the outlier roughly doubled MAE (0.1 → 0.199).
RMSE: squares first: , plus . Without the outlier, RMSE would be . So the outlier inflated RMSE from to — roughly a 10× blow-up.
Which reflects typical performance? 99% of predictions are off by only 0.1. MAE (0.199) stays closer to that typical value; RMSE (1.005) is dragged far above it by one point. If you want to describe the typical prediction, MAE is more honest here. If your goal is to not tolerate that one huge miss, RMSE's alarm is the feature you want. Same connection to Outlier detection and Bias-variance tradeoff (a single high-variance error dominates the squared metric).
Exercise 5.2 (L5)
Design an evaluation protocol for a house-price model. Prices range $50k–$5M. Stakeholders (a) are non-technical, (b) care enormously about catastrophic mispricings on luxury homes, (c) want to compare error fairly between cheap and expensive homes. Specify which metric(s) to report and why each requirement is met.
Recall Solution
No single metric satisfies all three, so report a small dashboard:
- RMSE (in $) — meets (b): squaring makes a $400k miss on a $3M mansion dwarf several $50k misses, so the metric screams about catastrophic luxury errors. Interpretable units satisfy (a) partly ("we're off by ~$X").
- MAPE or sMAPE (in %) — meets (c): dividing by the true price lets a $50k error on a $100k home (50%) and a $50k error on a $3M home (1.7%) be compared fairly. Percentages also satisfy (a) — non-technical stakeholders think in "we're 6% off." Use sMAPE if any listing can be near-zero or heavily discounted.
- MAE (in $) — a robust sanity check of typical error, so you can see whether RMSE is high because of systematic error (RMSE ≈ MAE) or a few disasters (RMSE ≫ MAE, from Exercise 3.2).
Validate all three under Cross-validation so the numbers aren't a lucky split, and stratify the folds by price band so luxury homes aren't accidentally all in one fold. Report: "Typical error (MAE) ≈ $X; outlier-sensitive error (RMSE) ≈ $Y; relative error (sMAPE) ≈ Z%." Three numbers, each meeting one requirement, together telling the full story.
Recall Quick self-test (cloze)
The metric with the same units as the target and equal weight per error is MAE. The metric preferred as a training loss because it is smooth/differentiable is MSE. RMSE equals MAE exactly when all absolute errors are identical (zero spread). The metric undefined when a true value is zero is MAPE. For any dataset, RMSE is always greater than or equal to MAE.