Loss Functions for Regression

Summarizing a regression model's errors in one number. Mean squared error, its root and mean absolute error computed by hand, why RMSE is never below MAE, the mean and median as the best constants under squared and absolute loss, Huber and quantile losses, what one bad value does to a fit and to a test score, MAPE and its pitfalls, and five models compared on held-out patients from a diabetes study.

Minimizing squared, absolute or pinball loss makes a model estimate the conditional mean, median or $\tau$-quantile of the outcome; for a single constant this is exact. RMSE lies between MAE and $\sqrt{n}$ times MAE, and their ratio is $\sqrt{\pi/2} = 1.2533$ for normal errors. Squared error is fragile. On one seeded split of a diabetes study (294 training, 148 test patients), one corrupted training value raised the least-squares slope on BMI from 9.97 to 15.53, while robust fits barely moved; one bad test value multiplied the test MSE by 5.25 and left the median absolute error unchanged. A 65-column model fits its training data best but has a test RMSE of 61.27, against 55.54 for three inputs. Percentage errors need an outcome with a true zero.

Simple Linear Regression fitted a line through five patients from a diabetes study, predicting disease progression after one year from body mass index. The line missed each patient by some amount, its residuals: $-11.83$, $-48.03$, $-15.76$, $+68.95$ and $+6.67$ progression units. To compare this line with another, or to say how well it predicts, those five numbers must be reduced to one. Squaring them and averaging gives one answer; taking their absolute values and averaging gives another; and the two answers rank models differently when a few errors are large.

A loss function assigns a cost to each error, and the average cost over a set of cases is a regression metric. This article covers the standard metrics, mean squared error, its square root and mean absolute error, and what each one measures. It derives which prediction each loss favors, introduces losses that resist outliers, and compares several models on patients they were not fitted to. The running example is the diabetes study of Efron, Hastie, Johnstone and Tibshirani (2004): 442 patients, ten baseline measurements and a measure of disease progression one year later.

Three metrics by hand

Write $e_i = y_i - \hat{y}_i$ for the residual of case $i$, the observed value minus the prediction, over $n$ cases. The three standard metrics are

$$\mathrm{MSE} = \frac{1}{n}\sum_{i=1}^{n} e_i^2, \qquad \mathrm{RMSE} = \sqrt{\mathrm{MSE}}, \qquad \mathrm{MAE} = \frac{1}{n}\sum_{i=1}^{n} |e_i|.$$

For the five patients:

Patient Residual $e$ $e^2$ $\lvert e \rvert$
1 −11.83 139.8 11.83
2 −48.03 2,306.7 48.03
3 −15.76 248.4 15.76
4 68.95 4,753.9 68.95
5 6.67 44.4 6.67
Sum 0 7,493.22 151.23

So $\mathrm{MSE} = 7{,}493.22/5 = 1{,}498.64$, $\mathrm{RMSE} = \sqrt{1{,}498.64} = 38.71$ and $\mathrm{MAE} = 151.23/5 = 30.25$. (The squares are computed from unrounded residuals.) The sum of squared residuals is the RSS that least squares minimized, so the MSE of a least-squares fit on its own data is RSS$/n$.

The units differ. MSE is in squared progression units, which have no direct meaning. RMSE and MAE are in progression units, the scale of the outcome: the line misses these patients by about 30 to 39 units. MAE is literally the average size of a miss. RMSE is a root-mean-square size, which weights large misses more heavily.

The weighting differs. Patient 4's residual of 68.95 is 45.6% of the sum of absolute residuals but 63.4% of the sum of squared residuals. Squaring makes a residual twice as large count four times as much, so MSE and RMSE are dominated by the largest errors, and MAE much less so.

RMSE is never below MAE

For any set of residuals, $\mathrm{RMSE} \ge \mathrm{MAE}$. The difference of their squares is

$$\mathrm{RMSE}^2 - \mathrm{MAE}^2 = \frac{1}{n}\sum_i |e_i|^2 - \Bigl(\frac{1}{n}\sum_i |e_i|\Bigr)^2,$$

which is the variance of the absolute residuals, and a variance is never negative. The two are equal only when every residual has the same size. The more the sizes of the errors vary, the more RMSE exceeds MAE, so the ratio RMSE/MAE is a rough indicator of how heavy the tail of large errors is. For normally distributed errors with mean 0 and standard deviation $\sigma$, the mean absolute error is $\sigma\sqrt{2/\pi}$ (Worked problem 2 derives it), so the ratio is $\sqrt{\pi/2} = 1.2533$. For the five patients it is $38.71/30.25 = 1.280$. In the other direction, $\mathrm{RMSE} \le \sqrt{n}\,\mathrm{MAE}$, with equality when one case carries all of the error. The reason is that $\sum_i e_i^2 \le \bigl(\sum_i |e_i|\bigr)^2$: the square of the sum adds the cross products $2|e_i||e_j|$, which are never negative and are all zero only when at most one $e_i$ is nonzero. Dividing by $n^2$ and taking square roots gives $\mathrm{RMSE}/\sqrt{n} \le \mathrm{MAE}$.

Since RMSE is an increasing function of MSE, the two always rank models in the same order. They carry the same information, and RMSE is usually reported because its units are those of the outcome.

What each loss is estimating

A loss function does more than score a model. It determines what a model fitted by minimizing it will estimate. The simplest case shows this exactly: predict every patient with one constant $c$, and ask which $c$ minimizes each loss.

Squared loss. The average squared error, $\frac{1}{n}\sum (y_i - c)^2$, has derivative $-\frac{2}{n}\sum (y_i - c)$, which is zero when $c = \frac{1}{n}\sum y_i = \bar{y}$. The best constant under squared loss is the mean.

Absolute loss. The average absolute error, $\frac{1}{n}\sum |y_i - c|$, is not differentiable where $c$ equals some $y_i$, but away from those points its slope is $\frac{1}{n}$ times (the number of $y_i$ below $c$ minus the number above). The slope is negative while fewer than half the values lie below $c$ and positive once more than half do, so the minimum is where the counts balance: the median.

For the 442 patients, the mean progression is 152.13 and the median 140.5. The distribution has a longer right tail (skewness 0.44), which pulls the mean above the median.

Constant prediction MSE RMSE MAE
mean, 152.13 5,929.9 77.01 65.76
median, 140.5 6,065.2 77.88 65.04
The error of predicting every patient's progression with one constant c. Mean squared error is a parabola with its minimum at the mean, 152.1. Mean absolute error is piecewise linear with its minimum at the median, 140.5. Each loss prefers its own center.
The error of predicting every patient's progression with one constant c. Mean squared error is a parabola with its minimum at the mean, 152.1. Mean absolute error is piecewise linear with its minimum at the median, 140.5. Each loss prefers its own center.

Each constant wins on its own loss. The same holds for models with inputs. A model fitted by minimizing squared error estimates the conditional mean of the outcome given the inputs, and one fitted by minimizing absolute error estimates the conditional median (Hastie, Tibshirani and Friedman, 2009, §2.4). Conditional Expectation and the Laws of Total Expectation and Variance proves the squared-error half: among all functions of the inputs, the conditional mean has the least expected squared error. The two coincide when the errors are symmetric about zero and differ when they are skewed. This is a reason to choose the loss deliberately: a hospital planning resources for an average patient wants the mean; a prediction meant to be "as likely too high as too low" for an individual is a median.

Each loss also corresponds to a model of the errors. Least squares is maximum likelihood when the errors are normal, the model behind the intervals of Linear Regression Assumptions. Least absolute deviations is maximum likelihood when the errors follow a Laplace (double exponential) distribution, whose heavier tails make large errors less surprising.

Quantile loss

Absolute loss is the special case $\tau = 1/2$ of the quantile or pinball loss. For a level $\tau$ between 0 and 1,

$$\rho_\tau(e) = \begin{cases} \tau\, e & e \ge 0, \\ (\tau - 1)\, e & e < 0, \end{cases}$$

which charges $\tau$ per unit for under-prediction and $1 - \tau$ per unit for over-prediction. The best constant follows from the slope, as for the median. Away from the data values, raising $c$ by a small amount lowers the loss of each of the $n_{>}$ values above $c$ at the rate $\tau$ and raises the loss of each of the $n_{<}$ values below it at the rate $1 - \tau$, so the average loss has slope $\bigl[(1 - \tau)\,n_{<} - \tau\,n_{>}\bigr]/n$. With $n_{<} + n_{>} = n$ this is $(n_{<} - \tau n)/n$: negative while fewer than a fraction $\tau$ of the values lie below $c$ and positive once more do. The minimum is where that fraction passes $\tau$, which is the $\tau$-quantile of the data. At $\tau = 1/2$ the two rates are equal and the argument is the one for the median. At $\tau = 0.9$ the best constant is the value with 90% of observations below it (Worked problem 1 finds it for the 442 patients). Koenker and Bassett (1978) introduced regression quantiles, linear models fitted by minimizing this loss; such a model describes how a chosen quantile of the outcome, rather than its mean, depends on the inputs. Quantile loss suits problems where the two directions of error have different costs, such as stocking enough supplies to meet demand nine days in ten.

Robustness to outliers

The weighting that makes squared error emphasize large residuals also makes it fragile. What a single value can do depends on how much each residual pulls on the fit, which is the derivative of the loss. For squared loss $e^2/2$, the pull is $e$ itself: a residual ten times larger pulls ten times harder, without limit. For absolute loss the pull is $\pm 1$ whatever the size of the residual. The Huber loss (Huber, 1964) is a compromise, quadratic for small residuals and linear for large ones:

$$\rho_\delta(e) = \begin{cases} \tfrac{1}{2} e^2 & |e| \le \delta, \\ \delta\,|e| - \tfrac{1}{2}\delta^2 & |e| > \delta. \end{cases}$$

Within $\delta$ of zero it behaves like least squares, which is efficient when errors are normal; beyond $\delta$ its pull is capped at $\delta$, as with absolute loss (Hastie et al., 2009, §10.6, who write the same loss scaled by 2). The threshold is stated in units of the residuals. scikit-learn's HuberRegressor estimates a scale for the residuals along with the coefficients and applies the threshold $\epsilon = 1.35$ (its default) to residuals divided by that scale (scikit-learn developers, 2026: documentation for version 1.9.1, checked 23 November 2026).

Left: squared, absolute and Huber losses (threshold 1) as functions of the residual. Right: their derivatives, the pull each residual exerts on the fit. The pull of a squared residual grows without limit; absolute and Huber losses cap it, so one wild value cannot drag the fit arbitrarily far.
Left: squared, absolute and Huber losses (threshold 1) as functions of the residual. Right: their derivatives, the pull each residual exerts on the fit. The pull of a squared residual grows without limit; absolute and Huber losses cap it, so one wild value cannot drag the fit arbitrarily far.

One bad value in the training data

To see the difference, the 442 patients were split at random into 294 for training and 148 for testing (scikit-learn's train_test_split, random_state=742), and progression was regressed on BMI three ways: by least squares, by least absolute deviations (median regression) and by Huber regression. Then one training value was corrupted. The training patient with the highest BMI, 42.2, had a progression of 242; it was changed to 2,420, the kind of error a misplaced decimal point produces. Each method was refitted, and every fit was scored on the 148 untouched test patients:

Method Training data Intercept BMI slope Test RMSE Test MAE
Least squares clean −105.97 9.974 59.39 49.99
Least squares one bad value −245.37 15.528 64.16 52.02
Least absolute deviations clean −153.98 11.531 58.00 47.70
Least absolute deviations one bad value −164.40 12.000 58.41 47.87
Huber clean −129.58 10.845 59.11 49.32
Huber one bad value −141.19 11.315 59.33 49.27
The 294 training patients, BMI against progression. One patient's progression of 242 (circled) was recorded as 2,420, far above the plot. The least-squares line swings up to chase it, its slope rising from 10.0 to 15.5. Least absolute deviations and Huber regression barely move from their clean fits.
The 294 training patients, BMI against progression. One patient's progression of 242 (circled) was recorded as 2,420, far above the plot. The least-squares line swings up to chase it, its slope rising from 10.0 to 15.5. Least absolute deviations and Huber regression barely move from their clean fits.

One value in 294 raised the least-squares slope by more than half, from 9.97 to 15.53, and its test RMSE from 59.4 to 64.2. The corrupted patient has the highest BMI in the training data, which gives it high leverage: a point at the edge of the input range can tilt the line most, as Linear Regression Assumptions explains. The two robust fits moved by less than half a unit of slope and their test errors barely changed. On the clean data the three methods differ too. Least absolute deviations fits the conditional median, and its line lies below the least-squares line at low BMI (76.6 against 93.5 at a BMI of 20), as expected for an outcome whose distribution is skewed to the right.

Robust losses are not a substitute for looking at the data. A value of 2,420 where every other value is below 350 should be found and corrected before any model is fitted. Robust fitting matters where bad values cannot all be found, as in large automated pipelines, or where the error distribution really does have heavy tails.

One bad value in the test data

The same fragility affects evaluation. The model with three inputs (BMI, blood pressure and the serum measurement S5), fitted to the clean training data, has test MSE 3,085.0, RMSE 55.54, MAE 45.48 and median absolute error 38.51. Changing one test patient's progression from 163 to 1,630, with the model's prediction for that patient 235.3, changes them as follows:

Metric Clean test data One bad value Factor
MSE 3,085.0 16,191.9 5.25
RMSE 55.54 127.25 2.29
MAE 45.48 54.41 1.20
Median absolute error 38.51 38.51 1.00

One value in 148 multiplied the MSE by five and more than doubled the RMSE. The MAE rose by a fifth, and the median absolute error did not move. A large gap between RMSE and MAE, or a sudden change in RMSE, is a reason to look at the largest residuals before drawing conclusions. The choice among these metrics should still follow from what the errors cost. If large errors are disproportionately harmful, RMSE measures what matters, and its sensitivity is the point. If every unit of error costs the same, MAE does.

Comparing models on held-out data

A metric computed on the data a model was fitted to measures fit, not prediction. Five least-squares models were fitted to the 294 training patients and evaluated on the 148 test patients. The models range from the training mean alone to all ten baseline variables with every square and pairwise product (degree 2, 65 columns), as in Multiple Linear Regression.

Model Columns Training RMSE Training MAE Test MSE Test RMSE Test MAE Test $R^2$
training mean only 0 78.77 67.69 5,476.2 74.00 64.10 −0.053
BMI 1 64.13 53.44 3,526.9 59.39 49.99 0.322
BMI, BP, S5 3 56.05 46.51 3,085.0 55.54 45.48 0.407
all ten 10 53.27 43.18 3,096.9 55.65 44.26 0.404
all ten, degree 2 65 47.32 37.04 3,754.3 61.27 48.14 0.278

Training error falls with every added column, from an RMSE of 78.8 to 47.3. Test error does not. The three-input and ten-input models are nearly tied on the test patients, and the degree-2 model, which fits its training data best by a wide margin, predicts new patients worse than either: its test RMSE of 61.3 is close to that of BMI alone. The gap between its training RMSE (47.3) and test RMSE (61.3) is the signature of overfitting described in The Bias-Variance Tradeoff.

The three metrics disagree in one place. By test RMSE the three-input model is slightly better than the ten-input model (55.54 against 55.65); by test MAE the ten-input model is better (44.26 against 45.48). A disagreement like this means the models differ in the shape of their errors rather than their size: the ten-input model has smaller typical errors and a larger worst error (163.2 against 153.2). With 148 test patients, though, differences this small are well within what a different random split could reverse. Cross-Validation averages over many splits, and significance tests ask whether a difference is larger than chance.

$R^2$ on test data is $1 - \mathrm{MSE}/\mathrm{MSE}_{\text{baseline}}$, the share of the baseline's squared error that the model removes. It has two common versions, which differ in the baseline. scikit-learn's r2_score, used in the table, compares the model with the mean of the test outcomes, a prediction that could only be made after seeing them. Compared instead with the training mean, an honest baseline, the values are higher here: 0.356 for BMI, 0.437 for the three-input model, and 0.000 for the training mean itself. The test patients in this split happen to average 141.1 against 157.7 in training, which is why the training mean scores $-0.053$ by scikit-learn's version. Either way, $R^2$ on new data can be negative, as Simple Linear Regression noted, and the version should be stated.

Percentage errors

Errors relative to the size of the outcome are popular in forecasting. The mean absolute percentage error is

$$\mathrm{MAPE} = \frac{100\%}{n}\sum_{i=1}^{n} \left|\frac{y_i - \hat{y}_i}{y_i}\right|.$$

For the three-input model on the test patients it is 49.2%, while the median absolute percentage error is 29.2%. The mean is pulled up by patients with small progression values: one patient with progression 25 and a prediction of 140 contributes an error of 460%. The 18 test patients with progression below 60 account for 37.5% of the MAPE. Hyndman and Koehler (2006) describe these problems in forecasting: percentage errors are undefined when an actual value is zero, extremely large when it is near zero, and meaningful only for outcomes on a scale with a true zero. Dividing the MAE by the mean outcome avoids the first two problems; here it is $45.48/141.1 = 32.2\%$. Progression scores are an index rather than a quantity with a natural zero, so percentage errors are a poor fit for this example.

Training loss and evaluation loss

The loss used to fit a model and the metric used to judge it need not be the same. Least squares is fitted by minimizing squared error, and it is reasonable to report its MAE as well, because MAE describes the typical size of an error in a way readers grasp. What matters is that the evaluation metric reflects what errors cost in the application, and that it is computed on data the model has not seen. When the two losses differ, the model is not optimizing what is being measured. If the measure is MAE and the errors are skewed, a model fitted by least absolute deviations can do better on it, as it did in the robust-fit table on the clean data (test MAE 47.70 against 49.99 for least squares). That is one split; how often it holds is one of the open questions below.

Worked problems

The problems extend the article on the 442 progression values of the diabetes study. The review-pass block of the article's script checks every number.

Problem 1 (the best constant for a 90% quantile). Under the pinball loss with $\tau = 0.9$, which constant prediction of progression is best for the 442 patients, and how does the slope argument of the quantile section single it out?

Solution. The slope of the average pinball loss between data values is $(n_{<} - \tau n)/n$, where $n_{<}$ counts the values below $c$. Here $\tau n = 0.9 \times 442 = 397.8$, not a whole number, so the slope changes sign at a single data value: the smallest $c$ with more than 397.8 values at or below it. Sorting the 442 progressions, 395 values lie below 265 and 398 are at or below it (three patients have exactly 265). Just below 265 the slope is $(395 - 397.8)/442 < 0$; just above, $(398 - 397.8)/442 > 0$. So the best constant is 265, the 398th smallest value, with an average pinball loss of 13.983, and a search over every distinct value confirms it. Had $\tau n$ been a whole number, the slope would have been zero between two consecutive order statistics, and every constant between them would be equally good, just as any value between the two middle observations is a median of an even number of values.

Problem 2 (the two bounds on RMSE). Prove that $\mathrm{RMSE}/\mathrm{MAE} = \sqrt{\pi/2}$ for normal errors with mean 0, and check both bounds on the five patients.

Solution. For $Z$ standard normal, by symmetry,

$$\mathbb{E}|Z| = 2 \int_0^\infty z\, \frac{e^{-z^2/2}}{\sqrt{2\pi}}\, dz = \frac{2}{\sqrt{2\pi}} \Bigl[-e^{-z^2/2}\Bigr]_0^\infty = \frac{2}{\sqrt{2\pi}} = \sqrt{2/\pi}.$$

An error $\sigma Z$ therefore has expected absolute value $\sigma\sqrt{2/\pi}$ and root mean square $\sigma$, so the ratio is $\sqrt{\pi/2} = 1.2533$; one million simulated normal draws give 1.2533 as well. For the five patients the bounds read $\mathrm{MAE} = 30.25 \le \mathrm{RMSE} = 38.71 \le \sqrt{5}\,\mathrm{MAE} = 67.63$, and the ratio 1.280 lies a little above the normal value. On the 148 test patients the ratio runs from 1.154 for the training mean to 1.273 for the degree-2 model (74.00/64.10 and 61.27/48.14 in the comparison table). The value for the mean is close to the ratio for a uniform distribution, $(1/\sqrt{3})/(1/2) = 1.155$, the ratio for errors with no tail at all. A ratio near or below 1.25 says that no small group of cases dominates the squared error; a ratio well above it, like the 2.34 of the corrupted test set in the body ($127.25/54.41$), says that a few do.

Problem 3 (Huber's center of the progression values). Compute the Huber estimate of the center of the 442 progressions, with scikit-learn's default threshold $\epsilon = 1.35$ applied to a scale fixed in advance at the normalized median absolute deviation. (scikit-learn's HuberRegressor instead estimates the scale jointly with the fit, so its answer on an intercept-only model would differ somewhat.) Then replace the largest value, 346, by 3,460 and recompute the mean, the median and the Huber estimate.

Solution. The Huber estimate $\hat{c}$ minimizes $\sum_i \rho_\delta(y_i - c)$. Its derivative is $-\sum_i \psi(y_i - c)$, where $\psi(e) = \max(-\delta, \min(\delta, e))$ is the residual clipped at $\pm\delta$. The sum is continuous and decreasing in $c$, so the root can be found by bisection. A robust scale comes from the median absolute deviation (MAD): the median is 140.5, the median of $|y_i - 140.5|$ is 59.5, and $1.4826 \times 59.5 = 88.21$ estimates the standard deviation (the factor makes the MAD consistent for a normal distribution). Then $\delta = 1.35 \times 88.21 = 119.09$. Bisection gives $\hat{c} = 149.84$, between the median (140.5) and the mean (152.13) and closer to the mean, because 399 of the 442 values lie within $\delta$ of it and are treated as by least squares.

After the corruption the mean rises by $(3{,}460 - 346)/442 = 7.05$, to 159.18, and the median stays at 140.5. The Huber estimate does not move at all. The value 346 was already $346 - 149.84 = 196.16$ above the center, beyond $\delta$, so its pull was already capped at $\delta$, and at 3,460 the pull is the same $\delta$. As long as a wild value stays beyond the threshold, its size does not matter. This is the bounded influence that the derivative plot of the robustness section shows, here in its exact form.

Open questions

  • Does least absolute deviations usually win on test MAE? On the one split of the article, median regression of progression on BMI had a lower test MAE than least squares (47.70 against 49.99). Repeating the split with 30 seeds, for the one-input and three-input models, and reporting the median and interquartile range of the paired differences would show whether this holds generally for an outcome with skewness 0.44.
  • How should the Huber threshold be chosen for prediction? scikit-learn's $\epsilon = 1.35$ is a convention. Tuning it by cross-validation on test MAE and on test RMSE, with and without the corrupted training value, would show whether the best threshold depends on which metric judges the model.
  • Which relative error measure suits an index with no natural zero? The article argues that percentage errors fit progression scores poorly. Comparing MAPE, MAE divided by the mean outcome, and an error scaled in the manner of Hyndman and Koehler (2006), dividing the MAE by that of the training-mean prediction, each computed with 30 seeded splits, would show which of them ranks the five models stably.

Where it leads

Each loss determines what a fitted model estimates: squared loss the conditional mean, absolute loss the median, pinball loss a chosen quantile. RMSE and MAE differ by how much a few large errors dominate, and a robust loss caps their pull on a fit. The next article, Training, Validation, and Test Sets, takes up the condition every comparison in this one relied on: that the errors were measured on patients the model was not fitted to.

In Python

import numpy as np
from sklearn.datasets import load_diabetes
from sklearn.linear_model import HuberRegressor, LinearRegression, QuantileRegressor
from sklearn.metrics import (mean_absolute_error, mean_squared_error,
                             median_absolute_error, r2_score, root_mean_squared_error)
from sklearn.model_selection import train_test_split

data = load_diabetes(scaled=False)
X, y = data.data[:, [2, 3, 8]], data.target          # BMI, BP, S5
X_tr, X_te, y_tr, y_te = train_test_split(X, y, test_size=1/3, random_state=742)

pred = LinearRegression().fit(X_tr, y_tr).predict(X_te)
print(mean_squared_error(y_te, pred))       # 3085.0
print(root_mean_squared_error(y_te, pred))  # 55.54
print(mean_absolute_error(y_te, pred))      # 45.48
print(median_absolute_error(y_te, pred))    # 38.51
print(r2_score(y_te, pred))                 # 0.407 (relative to the test-set mean)

# robust fits of progression on BMI alone
bmi_tr = X_tr[:, :1]
lad = QuantileRegressor(quantile=0.5, alpha=0, solver="highs").fit(bmi_tr, y_tr)
hub = HuberRegressor(epsilon=1.35, alpha=0).fit(bmi_tr, y_tr)
print(lad.intercept_, lad.coef_, hub.intercept_, hub.coef_)   # -153.98 [11.53] -129.58 [10.85]

The code was run with scikit-learn 1.5.2; the defaults it relies on are the same in the 1.9.1 documentation. root_mean_squared_error was added in scikit-learn 1.4; in earlier versions, take the square root of mean_squared_error. QuantileRegressor with quantile=0.5 fits least absolute deviations, and alpha=0 turns off its default L1 penalty. HuberRegressor also has a small default L2 penalty, alpha=0.0001, set to zero here. The numbers in this article are computed by tools/experiments/data-science/regression-loss-functions.py in the site's repository.

References

  • Efron, B., Hastie, T., Johnstone, I., and Tibshirani, R. (2004). Least angle regression. The Annals of Statistics, 32(2), 407–499. record · 21 pages
  • Hastie, T., Tibshirani, R., and Friedman, J. (2009). The Elements of Statistical Learning: Data Mining, Inference, and Prediction (2nd ed.). Springer. record · 39 pages
  • Huber, P. J. (1964). Robust estimation of a location parameter. The Annals of Mathematical Statistics, 35(1), 73–101. record
  • Hyndman, R. J., and Koehler, A. B. (2006). Another look at measures of forecast accuracy. International Journal of Forecasting, 22(4), 679–688. record
  • Koenker, R., and Bassett, G. (1978). Regression quantiles. Econometrica, 46(1), 33–50. record
  • scikit-learn developers (2026). HuberRegressor. scikit-learn 1.9.1 documentation. https://scikit-learn.org/1.9/modules/generated/sklearn.linear_model.HuberRegressor.html record

Reviewed: verified, 23 Nov 2026 · citations checked, 23 Nov 2026 · editorial review, 23 Nov 2026 · 4 revisions