Topic 3 of 6 · 5 min read
Regression error metrics: MAE, RMSE and MAPE
Goal: Choose between MAE, RMSE and MAPE for a forecasting task and explain how outliers change each one.
Regression metrics turn prediction errors into one number, and the choice of metric decides how much a few large mistakes, or a few tiny true values, count. MAE, RMSE and MAPE can rank the same two models in opposite orders.
Check yourself · 1 of 3
Which metric is most affected by one very large prediction error?
Why it matters
A demand forecast that is off by 5 units a day and one that is perfect most days but off by 200 once a month have the same average error. Which one hurts depends on the business, and the metric should say so.
The three metrics
With errors e = prediction - actual:
- MAE (mean absolute error): the average of
|e|. Same unit as the target. Every unit of error counts the same. Robust to outliers. - RMSE (root mean squared error): the square root of the average of
e². Same unit as the target. Squaring makes large errors count much more. One error of 100 weighs as much as 100 errors of 10 in the squared sum. - MAPE (mean absolute percentage error): the average of
|e| / |actual|. Unit-free, so it compares across products of different sizes. It explodes when actual values are near zero and is undefined at zero.
import numpy as np
e = np.array([2, -3, 1, 40]) # one big miss
mae = np.abs(e).mean() # 11.5
rmse = np.sqrt((e**2).mean()) # 20.1
The gap between RMSE and MAE tells you about outliers: when they are close, errors are similar in size; when RMSE is much larger, a few errors dominate.
Before and after
A team compares two forecasters. Before: "Model B is better, its MAPE is 8% against 11%." After checking: many daily sales are 0 to 3 units, so MAPE is dominated by those days. On MAE in units, Model A is better by 0.4 units a day, and on RMSE they tie. The stock-out cost is driven by big misses, so they use RMSE and look at the worst 10 days.
How to choose
- Costs grow with the size of the error, and big misses are disproportionately bad: RMSE.
- Costs grow roughly in line with error size, and the data has outliers: MAE.
- Targets span orders of magnitude and are never near zero: MAPE, or a log-error variant.
What goes wrong
- MAPE with zeros or small actuals. One day with actual 0.1 and prediction 1 contributes 900%.
- MAPE favours under-forecasting. It caps over-prediction errors at no limit but under-prediction at 100%, so biased low models can look better.
- Mixing units. Comparing RMSE across targets in different units tells you nothing.
- Reporting only an average. Show a quantile of absolute error (the median, the 90th percentile) next to it.
Examples
One outlier, three metrics
Errors of 2, -3, 1 and 40 units. MAE is 11.5. RMSE is about 20.1. Remove the 40 and the errors are 2, -3 and 1: MAE 2.0 and RMSE 2.2. The single large miss moved MAE by a factor of about six and RMSE by a factor of about nine.
MAPE on small numbers
A shop sells 0 to 3 of a niche item per day. Predicting 2 when 1 sold is a 100% error; predicting 1 when 0.5 sold is 100% too, and an actual of 0 cannot be scored at all. A product that sells 400 units a day with an error of 20 scores 5%. MAPE then says the niche item is the worst forecast, which says nothing about money.
Key points
- MAE averages absolute errors in the target's own unit and treats every unit of error equally.
- RMSE squares errors before averaging, so a few large misses dominate it.
- MAPE is unit-free but breaks down when actual values are zero or close to it.
- A large gap between RMSE and MAE signals that a few outlier errors drive the score.
- Pick the metric from how the cost of an error grows, and show a quantile of error beside the mean.
Common mistakes
- Using MAPE on targets that include zeros or values near zero.
- Choosing RMSE by habit when outliers are data errors rather than real costly events.
- Comparing RMSE values from targets with different units or scales.
- Reporting a single average error with no look at its worst cases.
Check yourself · 2 of 3
A demand forecast covers items that sometimes sell 0 units in a day. Why is MAPE a poor fit?
Check yourself · 3 of 3
RMSE is 18 and MAE is 4 on the same forecasts. What does the big gap suggest?
Practice items, not counted towards your mastery.
Start here
- Google ML Crash Course: classification (opens in a new tab)CourseFree
Accuracy, precision, recall and ROC/AUC explained with worked confusion-matrix numbers.
- scikit-learn: metrics and scoring (opens in a new tab)DocsFree
The reference for every metric named in this skill, with the exact function and its edge cases.
- scikit-learn: probability calibration (opens in a new tab)DocsFree
Reliability curves, Brier score and the sigmoid and isotonic recalibration methods, with plots.
More for this topic
- scikit-learn: mean_absolute_percentage_error (opens in a new tab)DocsFree
Defines MAPE and notes how it behaves when true values are close to zero.