How MAE reacts to individual large forecast errors: linear, unbounded contribution without saturation
MAE counts each prediction error linearly and without a cap: one large error shifts the metric by its magnitude divided by n. Outlier robustness means no quadratic amplification, not insensitivity to extreme errors.
On this page
Key idea
MAE is the mean of absolute errors, so each observation contributes its full absolute deviation divided by the number of samples. The contribution is linear and unbounded: doubling an error doubles its contribution, and there is no cap. This makes MAE more robust to outliers than squared error, where a large error is amplified quadratically, but robustness is not insensitivity. A single large error still shifts MAE by exactly its magnitude divided by n. Use MAE when the target functional is the median and error cost is proportional to magnitude; otherwise align the metric with the actual decision-theoretic functional.
Context and recommendation: MAE as a mean of absolute deviations
The mean_absolute_error function in scikit-learn computes a risk metric corresponding to the expected value of the absolute error loss, the l1-norm loss. Formally, MAE(y, y_hat) = (1/n) * sum over samples of |y_i - y_hat_i|. The function accepts y_true and y_pred of shape (n_samples,) or (n_samples, n_outputs), an optional sample_weight, and a multioutput parameter that defaults to uniform_average. The returned value is a non-negative float whose best value is 0.0.
The practical consequence of this definition is that every sample enters the sum with its full absolute deviation. There is no transformation, clipping, or saturation: an error of magnitude 100 contributes exactly 100 to the numerator before division by n. If you are free to choose a scoring function, statistical decision theory as summarized in the scikit-learn user guide recommends picking a strictly consistent scoring function for your target functional, and using it both as the training loss and as the evaluation metric. For the median functional, that consistent choice is absolute error loss.
from sklearn.metrics import mean_absolute_error
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
print(mean_absolute_error(y_true, y_pred))
# 0.5Mechanics of a single error: linear and unbounded contribution
Because MAE is an arithmetic mean of per-sample absolute deviations, one observation with error e changes the metric by exactly e/n relative to a baseline where that error is zero. Doubling the error doubles the shift; there is no quadratic amplification and no cap. This is what linear and unbounded means in practice: the derivative of the contribution with respect to the error magnitude is constant at 1/n for all magnitudes.
The following illustrative example uses the documented scikit-learn inputs and then inflates one error to show the linear shift. The first case reproduces the documented output of 0.5. The second case changes only the last prediction so its error grows from 1 to 10; the metric rises to (0.5 + 0.5 + 0 + 10) / 4 = 2.75, which is exactly 10/4 added by that single point. The output values shown are illustrative computations consistent with the documented behavior of mean_absolute_error.
from sklearn.metrics import mean_absolute_error
y_true = [3, -0.5, 2, 7]
y_pred = [2.5, 0.0, 2, 8]
print(mean_absolute_error(y_true, y_pred)) # 0.5
# Inflate the last prediction so its error grows from 1 to 10
y_pred_inflated = [2.5, 0.0, 2, 17]
print(mean_absolute_error(y_true, y_pred_inflated)) # 2.75Trade-offs: outlier robustness is not insensitivity
The common statement that MAE is robust to outliers needs qualification. Robustness here means that, compared with squared error, a large error is not amplified quadratically and therefore does not dominate the aggregate to the exclusion of all small errors. Under squared loss, an error of 10 contributes 100 while an error of 1 contributes 1; under absolute loss, they contribute 10 and 1. The relative weight of the outlier drops, but its absolute contribution is still its full magnitude.
So MAE is not blind to extreme errors. Each outlier is counted completely, once, with weight 1/n. If your evaluation set has one catastrophic prediction among thousands of good ones, MAE will register it, but its effect on the reported number may look small. That is a reason to complement MAE with a look at the distribution of absolute errors, such as the maximum or a high quantile, when large individual errors carry disproportionate business risk.
from sklearn.metrics import mean_absolute_error, mean_squared_error
y_true = [1, 1, 1, 100]
y_pred = [1, 1, 1, 1]
mae = mean_absolute_error(y_true, y_pred)
mse = mean_squared_error(y_true, y_pred)
print(f"MAE: {mae:.4f}, MSE: {mse:.4f}")
# MAE: 24.7500, MSE: 2450.2500Applicability limits: when linear contribution matches the task
The scikit-learn user guide, following Gneiting and colleagues, frames metric selection through the target functional of the conditional distribution of Y given X: the mean, median, or a quantile. Absolute error loss is the strictly consistent scoring function for the median, and squared error is consistent for the mean. If your goal is a quantile, as in the guide's network-reliability example where a provider promises customers that at least 99 percent of days have interruptions under one minute, the consistent choice is pinball loss, used both for training (for example HistGradientBoostingRegressor with loss='quantile') and for evaluation.
Choosing MAE therefore makes sense when the median is the target and the cost of an error grows proportionally with its magnitude. If the cost structure differs, for example errors beyond a threshold are equally damaging regardless of size, or the target is the mean, the metric should be changed to match; MAE's linear, unbounded contribution is a property to be matched against the problem, not a universal virtue. Note also that the equal-weight linearity described here holds for the default uniform averaging; with sample_weight or multioutput aggregation such as raw_values or explicit output weights, the proportions change accordingly.
from sklearn.metrics import mean_absolute_error
y_true = [[0.5, 1], [-1, 1], [7, -6]]
y_pred = [[0, 2], [-1, 2], [8, -5]]
print(mean_absolute_error(y_true, y_pred))
# 0.75
print(mean_absolute_error(y_true, y_pred, multioutput='raw_values'))
# [0.5, 1.0]Applicability
- Is the business cost of a prediction error proportional to its magnitude, or does it grow faster (favoring squared loss) or saturate (favoring quantile or threshold metrics)?
- Is the target functional the median? If the goal is the mean, squared error is the consistent choice; for a quantile, use pinball loss.
- Are sample_weight or multioutput settings in use? Equal-weight linearity of per-sample contribution changes under weighted aggregation.
- Is the metric used both for training loss and evaluation, or only for evaluation? Training behavior with MAE loss depends on the specific algorithm.
- Does the evaluation set contain outliers whose full linear contribution you intend to count, or should they be handled separately before scoring?
Where this applies
The linear-contribution analysis applies to the aggregated metric with equal weights; sample_weight, multioutput aggregation, and algorithm-specific training behavior with MAE loss are outside its scope. Numeric values shown are illustrative, not observations from real datasets.