Median Error and Large Misses: Compute absolute residuals, Compare median and mean, Inspect the largest misses

Why Median Absolute Error Can Hide a Large Regression Miss

Compare median absolute error with MAE on the same predictions, then inspect the largest misses before choosing a regression model.

A low median absolute error does not mean that every regression prediction is close to its target. It describes the middle of the absolute-error distribution, so a small number of very large misses can barely affect it. When those misses matter operationally, report the median alongside the mean absolute error and inspect the worst cases rather than selecting a model from one reassuring number.

Start with absolute residuals, not a percentage

For each evaluated row, subtract the prediction from the actual target and take the absolute value. The median absolute error is the median of those non-negative values. Its best possible value is zero, and for a single target it uses that target’s units. If the target measures minutes, an error of one means one minute, not one percent or one unit of accuracy.

The mean absolute error, often abbreviated MAE, averages the same absolute residuals instead. Do not shorten both metric names to MAE in a report: use an explicit label such as median absolute error or MedAE for the median. Neither metric tells you whether predictions tend to be too high or too low, because taking absolute values removes the sign.

Reproduce a disagreement with five predictions

The following synthetic example needs Python and scikit-learn in your selected environment. It trains nothing, reads no production data and writes no files. It deliberately includes one large miss so the difference is easy to inspect.

from sklearn.metrics import mean_absolute_error, median_absolute_error

actual = [10, 10, 10, 10, 10]
predicted = [10, 11, 9, 12, 110]
errors = [abs(a - p) for a, p in zip(actual, predicted)]

median_error = median_absolute_error(actual, predicted)
mean_error = mean_absolute_error(actual, predicted)
print("Absolute errors:", errors)
print("Median absolute error:", median_error)
print("Mean absolute error:", mean_error)
assert median_error == 1.0
assert mean_error == 20.8

The absolute errors are 0, 1, 1, 2 and 100. Their middle value is 1, while their average is 20.8. These are results from an invented teaching dataset, not performance claims about a deployed model. The median is not broken: it answers a different question from the average. With an even number of unweighted observations, the usual median averages the two central sorted errors.

Check what happens when the worst miss grows

Replace the last prediction of 110 with 1010. The final absolute error becomes 1000, but the middle sorted error remains 1. The mean rises to 200.8. This is why a median-only dashboard may stay flat while a damaging tail problem gets worse.

That resistance can be useful when you want a stable summary of central performance. It does not justify deleting the difficult row. Investigate its source record, units, missing inputs and whether similar cases are likely in real use. Correct an established data error with a documented rule; do not remove legitimate hard examples merely to improve the score.

Build a small evaluation checklist

  1. Use the same held-out rows and the same target units for both metrics. Keep preprocessing fitted only on training data.
  2. Record the number of evaluated rows. A five-row demonstration is not evidence of production reliability.
  3. Inspect the largest absolute residuals and their signed residuals to understand magnitude and direction.
  4. Break down results by relevant operating groups when you have enough observations, rather than allowing a large easy group to hide a small difficult one.
  5. Choose acceptance criteria from the consequences of errors before comparing candidate models. Avoid repeatedly tuning against a final test set.

If a relative metric also looks surprising, see why MAPE becomes large near zero actual values. That is a separate denominator problem: a median in target units does not share MAPE’s percentage interpretation.

Questions to settle before publishing a score

Does a median of zero prove perfect predictions? No. For example, a majority of exact predictions can give a zero median while other rows still have substantial errors. Inspect the individual residuals.

What changes for multiple targets? The API offers per-output results through multioutput='raw_values' and aggregation options. Review each output before averaging, especially when their units differ. Do not treat an average of several output medians as the median of every individual error pooled together.

Where is the definition documented? Read the official scikit-learn median_absolute_error reference for parameters, sample weighting and multioutput handling. This example uses neither sample weights nor multiple outputs.

This tutorial is for educational purposes. Test changes carefully before production use. The site owner is not responsible for misuse, damage, data loss or production issues.

Leave a Reply

Your email address will not be published. Required fields are marked *