Sub topic 4
Why RMSE reacts more strongly to large errors than MAE
This chapter assumes you can compute residuals, MAE, MSE, and RMSE with NumPy, as covered in the earlier chapters. You should also be comfortable with the mean and the square root.
The same total error, spread differently
MAE and RMSE both summarize the size of the errors in the original units of the target. They can still disagree about the same model. The difference comes from what each one does to an error before averaging it.
- MAE takes the absolute value. An error of 4 counts as 4.
- RMSE squares the error first. An error of 4 counts as 16 before the average is taken, and the square root is applied at the end.
Squaring makes big errors grow faster than small ones. An error of 1 stays 1, an error of 2 becomes 4, and an error of 4 becomes 16. When these are averaged, the large errors dominate the sum.
The next example uses two sets of errors with the same total absolute error.
import numpy as np
# Same total absolute error, different spread.
spread_evenly = np.array([1.0, 1.0, 1.0, 1.0])
one_big_miss = np.array([0.0, 0.0, 0.0, 4.0])
for errors in (spread_evenly, one_big_miss):
mae = np.mean(np.abs(errors))
rmse = np.sqrt(np.mean(errors ** 2))
print(mae, rmse)
# Both have MAE 1.0. RMSE is 1.0 for the first and 2.0 for the second.Both sets have an MAE of 1.0. The RMSE is 1.0 for the evenly spread errors and 2.0 for the single large miss. MAE cannot tell these two models apart. RMSE can.
What the numbers mean
If every error has the same absolute size, MAE and RMSE are equal. In every other case RMSE is larger than MAE. So RMSE is never smaller than MAE, and the gap between them tells you something about the errors.
| Comparison | What it suggests |
|---|---|
| RMSE is close to MAE | Errors are similar in size |
| RMSE is much larger than MAE | A few errors are much larger than the rest |
The ratio RMSE / MAE is a quick check for this. In the example above it is 1.0 for the even errors and 2.0 for the one big miss.
Why the square root does not undo this
The square root brings RMSE back to the original units, but it does not restore equal weighting. The square root is applied once, to the average of the squared errors. It does not act on each error separately. The large errors have already dominated the average by that point.
You can see it in the one-big-miss case. The mean of the squared errors is (0 + 0 + 0 + 16) / 4 = 4. The square root of 4 is 2. The single error of 4 accounts for all of that value.
An outlier test
You can measure the effect directly. Take a set of small errors, then replace one with a large value, and watch how each metric moves.
import numpy as np
errors = np.array([1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0])
def report(label, e):
mae = np.mean(np.abs(e))
rmse = np.sqrt(np.mean(e ** 2))
print(f"{label}: MAE={mae:.2f} RMSE={rmse:.2f}")
report("no outlier", errors)
with_outlier = errors.copy()
with_outlier[-1] = 10.0
report("one outlier", with_outlier)This prints the following.
no outlier: MAE=1.00 RMSE=1.00
one outlier: MAE=1.90 RMSE=3.31One error of 10 raises MAE from 1.00 to 1.90, which is a rise of 90 percent. RMSE rises from 1.00 to 3.31, which is more than triple.
Practical consequences
- Use RMSE when large errors are especially costly. A forecast that is off by 10 can do much more damage than ten forecasts that are off by 1. RMSE penalizes that case more heavily.
- Use MAE when every unit of error costs about the same, or when a few extreme values in the data are noise you do not want to dominate the score.
- Report both when you can. The gap between them describes the shape of your errors.
Common mistakes
- Comparing an RMSE from one dataset to an MAE from another. They differ in weighting, so compare like with like.
- Expecting RMSE to equal MAE. They are equal only when all absolute errors are identical.
- Dropping outliers just to improve RMSE. First check whether they are real cases your model must handle.
Exercise
A model has absolute errors [2, 2, 2, 2] on four test points. A second model has absolute errors [0, 0, 0, 8]. Compute MAE and RMSE for each. Which metric separates them, and why?
Show answer
Model 1: MAE = 2, RMSE = sqrt((4+4+4+4)/4) = sqrt(4) = 2. Model 2: MAE = (0+0+0+8)/4 = 2, RMSE = sqrt((0+0+0+64)/4) = sqrt(16) = 4. The MAE values are equal, so MAE cannot separate the models. RMSE separates them because squaring makes the single error of 8 count as 64, which dominates the average.
Exercise
On a test set, MAE is 5.0 and RMSE is 5.1. What does this say about the errors? What would you suspect if RMSE were 12.0 with the same MAE?
Show answer
An RMSE close to MAE means the errors are all similar in size, with no large outliers. An RMSE of 12.0 against an MAE of 5.0 means a few errors are much larger than the rest, so you should inspect the largest residuals.