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, and that you know a residual is predicted value minus true value. Here you will see why squaring makes RMSE react to large misses, how to measure that reaction, and what it means when you pick a metric.
The core idea
MAE adds up the sizes of the errors and divides by the count. Every unit of error counts the same. A miss of 4 counts four times as much as a miss of 1.
RMSE squares each error before averaging. A miss of 4 becomes 16, and a miss of 1 stays 1. The big miss now counts sixteen times as much, not four. After averaging, the square root brings the result back to the target's original units, but it does not undo the extra weight.
The following table shows how the penalty grows with the size of one error.
| Error size | Contribution to MAE sum | Contribution to MSE sum |
|---|---|---|
| 1 | 1 | 1 |
| 2 | 2 | 4 |
| 3 | 3 | 9 |
| 4 | 4 | 16 |
| 10 | 10 | 100 |
MAE grows linearly with error size. MSE grows with the square. Doubling an error doubles its MAE contribution and quadruples its MSE contribution.
Same MAE, different RMSE
Take two sets of four 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.MAE cannot tell these two error sets apart. Both average 1.0. RMSE gives 1.0 for the even set and 2.0 for the set with one big miss.
You can work out the second RMSE by hand. The squared errors are 0, 0, 0, and 16. Their mean is 4, and the square root of 4 is 2.
A useful relationship: RMSE is never below MAE
For any set of errors, RMSE is greater than or equal to MAE. The two are equal only when every error has the same absolute size. This is a standard result about averages: the root of the mean of squares is at least the mean of absolute values.
That gives you a diagnostic. The ratio RMSE / MAE tells you how uneven the errors are.
- A ratio near 1 means the errors are close to the same size.
- A larger ratio means a few errors are much bigger than the rest.
In the example above, the ratio is 1.0 for the even set and 2.0 for the set with one big miss.
There is also an upper bound. With n errors, RMSE / MAE can never exceed the square root of n. The maximum occurs when a single error holds all the loss, as in the second set. With n = 4, the bound is 2, and that set reaches it.
import numpy as np
def error_summary(errors):
errors = np.asarray(errors, dtype=float)
mae = np.mean(np.abs(errors))
rmse = np.sqrt(np.mean(errors ** 2))
return mae, rmse, rmse / mae
cases = {
"even": [1.0, 1.0, 1.0, 1.0],
"mild spread": [0.5, 1.0, 1.0, 1.5],
"one big miss": [0.0, 0.0, 0.0, 4.0],
}
for name, errs in cases.items():
mae, rmse, ratio = error_summary(errs)
print(f"{name:13s} MAE={mae:.3f} RMSE={rmse:.3f} ratio={ratio:.3f}")Running this prints a ratio of 1.000 for the even case, about 1.061 for the mild spread, and 2.000 for the one big miss. All three cases have the same MAE of 1.0.
Watching one outlier move each metric
Now see what happens as one error grows while the others stay fixed. Start with ten errors of size 1, then replace one of them with a larger value.
import numpy as np
base = np.ones(10)
for big in (1, 2, 5, 10, 20):
errors = base.copy()
errors[-1] = big
mae = np.mean(np.abs(errors))
rmse = np.sqrt(np.mean(errors ** 2))
print(f"outlier={big:2d} MAE={mae:.3f} RMSE={rmse:.3f}")The output is:
outlier= 1 MAE=1.000 RMSE=1.000
outlier= 2 MAE=1.100 RMSE=1.153
outlier= 5 MAE=1.400 RMSE=1.795
outlier=10 MAE=1.900 RMSE=3.209
outlier=20 MAE=2.900 RMSE=6.223When the outlier grows from 1 to 20, MAE rises from 1.0 to 2.9, a factor of 2.9. RMSE rises from 1.0 to about 6.2, a factor above six. MAE moves in a straight line with the outlier. RMSE accelerates.
Why the square root does not cancel the effect
A common misunderstanding is that the final square root reverses the squaring. It does not, because the root is applied after the average, not to each error.
Compare two operations on the errors 3 and 1.
- Taking the root of each square first returns the absolute values, 3 and 1. Their mean is 2. This is MAE.
- Squaring first gives 9 and 1. The mean is 5, and the root is about 2.236. This is RMSE.
Because the mean sits between the two operations in RMSE, the large value gets extra weight before the root shrinks the total. The result, 2.236, is pulled toward the larger error of 3.
The square root does one useful thing. It restores the original units, so RMSE of 2.236 dollars is comparable to the errors in dollars. MSE would be in squared dollars, which is hard to interpret.
Why this happens: the mean and the median
There is a deeper way to see the difference. Each metric corresponds to a different "best constant guess."
- The constant that minimizes squared error is the mean of the target values.
- The constant that minimizes absolute error is the median.
The mean is pulled toward extreme values. The median ignores how extreme they are and cares only about ordering. This is the same difference you see in summary statistics: one billionaire raises an average income a lot and leaves the median almost unchanged.
A model trained to minimize squared error behaves like the mean. A model trained to minimize absolute error behaves like the median. When you evaluate with RMSE, you reward models that avoid large misses. When you evaluate with MAE, you reward models that are typically close.
The following snippet checks this numerically for a skewed set of values.
import numpy as np
y = np.array([1.0, 2.0, 2.0, 3.0, 100.0])
candidates = np.linspace(0, 100, 10001)
mse_curve = [np.mean((y - c) ** 2) for c in candidates]
mae_curve = [np.mean(np.abs(y - c)) for c in candidates]
print("best for squared error :", candidates[np.argmin(mse_curve)])
print("best for absolute error:", candidates[np.argmin(mae_curve)])
print("mean:", y.mean(), "median:", np.median(y))The squared-error minimizer lands at 21.6, which is the mean. The absolute-error minimizer lands at 2.0, which is the median. The single value of 100 drags the mean far from where most values sit.
Edge cases and gotchas
Many small errors can hide inside RMSE
RMSE is dominated by the largest errors. If a model is excellent on 95 percent of rows and terrible on 5 percent, RMSE reflects mostly the 5 percent. That may be what you want, or it may hide that the model is good for typical cases. Report MAE alongside RMSE so a reader can see both.
Noisy labels and bad data
If some target values are wrong (a sensor glitch, a data entry mistake), any model will show a huge residual on those rows. RMSE amplifies them. A change in RMSE between two models may then reflect how each handles a few corrupt rows, not how well each fits the real signal. Check the largest residuals before drawing conclusions.
import numpy as np
def worst_residuals(y_true, y_pred, k=3):
y_true = np.asarray(y_true, dtype=float)
y_pred = np.asarray(y_pred, dtype=float)
residuals = y_pred - y_true
order = np.argsort(-np.abs(residuals))[:k]
return [(int(i), float(residuals[i])) for i in order]
y_true = [3.0, 5.0, 2.5, 7.0, 4.0]
y_pred = [2.5, 5.0, 4.0, 8.0, 14.0]
print(worst_residuals(y_true, y_pred))This prints the row indices and signed residuals of the three worst predictions, with row 4 (residual 10.0) first.
Sample size matters less than you might expect
The gap between RMSE and MAE does not shrink just because you have more data. It depends on the shape of the error distribution. For errors that follow a normal distribution, RMSE is about 1.25 times MAE. A ratio far above that suggests heavy tails: a handful of big misses.
The comparison is only fair on the same data
RMSE and MAE values are comparable only between models scored on the same rows. Removing the outliers from the test set lowers RMSE more than it lowers MAE, so changing the set changes the ratio.
Connecting the metric to cost
The choice follows from the cost of mistakes.
- If cost grows in proportion to the error (a delivery that is 2 hours late costs twice as much as 1 hour late), MAE matches that cost directly.
- If cost grows faster than the error (a structural load estimate that is far too low can cause failure), RMSE matches that worry better, because it punishes large misses more.
The next chapters build on this. The predict-the-mean baseline uses the same squared-error idea, and R squared is built from squared errors, so R squared inherits RMSE's sensitivity to large misses.
Summary of the key differences
| Property | MAE | RMSE |
|---|---|---|
| Units | Same as target | Same as target |
| Penalty growth | Linear in error size | Quadratic before the root |
| Best constant predictor | Median | Mean |
| Reaction to one outlier | Moderate | Strong |
| Relationship | Always at most RMSE | Always at least MAE |
| Upper bound on RMSE / MAE | Not applicable | Square root of n |
Exercise
A model makes five errors with absolute sizes 1, 1, 1, 1, and 6. Compute MAE and RMSE, then say what the RMSE / MAE ratio tells you.
Show answer
MAE = (1 + 1 + 1 + 1 + 6) / 5 = 2.0. The squared errors are 1, 1, 1, 1, and 36, which sum to 40. The mean is 8, so RMSE = sqrt(8), about 2.828. The ratio is about 1.414, well above 1, which shows the errors are uneven because one large miss dominates. The upper bound for n = 5 is sqrt(5), about 2.236, so this set is below the maximum but clearly not uniform.
Exercise
Two models have the same MAE of 2.0 on a test set. Model A has RMSE 2.1 and Model B has RMSE 3.5. You are predicting loads where a large underestimate is dangerous. Which model do you prefer, and why?
Show answer
Prefer Model A. The equal MAE means both are about equally close on average. The much higher RMSE for Model B means it makes some large errors, and large misses are the costly case here. Before deciding, inspect Model B's largest residuals to confirm they are real and not caused by bad labels.