Huber loss
Huber loss is a loss function for regression that is quadratic for small errors and linear for large ones, so it behaves like squared loss near zero and like absolute loss (L1 loss) in the tails. It comes from the Swiss statistician Peter J. Huber's 1964 paper "Robust Estimation of a Location Parameter", which derived it as the most robust choice within a class of estimators he named M-estimators, for normal data contaminated by a fraction of gross errors.[1] A single threshold parameter, usually written $\delta$ (Huber used $k$), sets where the quadratic part hands over to the linear part.[1][5] The loss is used in robust linear regression and gradient boosting, and in deep learning both directly and in a rescaled form called smooth L1 loss, which the Fast R-CNN object detection network introduced for bounding-box regression.[7][12][14] Clipping the error term in DeepMind's 2015 deep Q-network gives the same gradients as using it, and later DQN implementations apply it explicitly.[9][10][11]
Definition
For a residual $a = y - \hat{y}$ (the difference between a target $y$ and a prediction $\hat{y}$) and a threshold $\delta > 0$, the Huber loss is
This is the form used by PyTorch's HuberLoss and Keras's Huber, both with a default $\delta$ of 1.0.[5][18] Huber's 1964 paper wrote the same function as $\rho(t) = \frac{1}{2}t^2$ for $|t| < k$ and $\rho(t) = k|t| - \frac{1}{2}k^2$ for $|t| \ge k$.[1] Over a dataset the per-example losses are usually averaged, which is the default reduction in both libraries.[5][18]
The two branches meet with the same value and the same slope at $|a| = \delta$, so the loss is continuous and has a continuous first derivative. Its derivative is the residual clipped to the interval $[-\delta, \delta]$:
Inside the threshold the gradient grows in proportion to the error, as it does for mean squared error; outside, its magnitude is fixed at $\delta$, as for mean absolute error, so a single very large residual cannot dominate an update. PyTorch's documentation describes the same trade: the linear region makes the loss "less sensitive to outliers" than the mean squared error, while the quadratic region gives it smoothness near zero that the L1 loss lacks.[5] The second derivative is 1 inside the threshold and 0 outside, so it jumps at $|a| = \delta$. The pseudo-Huber loss (below) is a smooth approximation that is twice continuously differentiable, a property cited by XGBoost and in consistency-model training.[19][21]
Limiting cases
The threshold moves the loss between its two parents. As $\delta \to \infty$ the quadratic branch covers every residual and the loss approaches half the squared error; as $\delta \to 0$ the loss itself goes to zero, but divided by $\delta$ it approaches the absolute error.[6] In Huber's location problem the corresponding estimators are the sample mean ($k = \infty$) and the sample median ($k = 0$), which he identified as the limiting cases of his estimator for contamination fractions of 0 and 1.[1]
Origin in robust statistics
Huber, born in 1934 in Wohlen, Switzerland, took a diploma and a doctorate in mathematics at ETH Zurich and then spent 1961 to 1963 as a postdoctoral researcher in the statistics department at Berkeley, where he wrote the 1964 paper.[2] In a 2008 interview he said his thesis had been in pure mathematics, that van der Waerden's book and his study of Abraham Wald's decision theory had convinced him a theory of robustness would have to come through decision theory, and that the core of the paper was his discovery about a year later that certain M-estimates have an asymptotic minimax property. He also said John Tukey's 1960 paper on sampling from contaminated distributions had certainly influenced him and that, although he did not remember when he first read it, it must have been early in his time at Berkeley. He added that the paper was submitted in the spring or summer of 1963.[2] It appeared in The Annals of Mathematical Statistics in March 1964.[1]
The paper starts from least squares. Huber noted that Gauss chose the normal distribution and quadratic loss mainly for computational convenience, and that the sample mean can perform very badly when the true distribution departs only slightly from the normal.[1] He modeled that departure as contamination: observations follow $F = (1 - \epsilon)\Phi + \epsilon H$, where $\Phi$ is the standard normal distribution, $\epsilon$ is a known fraction of gross errors and $H$ is an unknown contaminating distribution.[1]
He then studied estimators $T$ defined by minimizing $\sum_i \rho(x_i - T)$ for some function $\rho$, which he called M-estimators. The class includes the sample mean ($\rho(t) = t^2$), the sample median ($\rho(t) = |t|$) and every maximum likelihood estimator ($\rho = -\log f$ for a density $f$).[1] Measuring robustness by the worst-case asymptotic variance over the contaminated family, he showed that the most robust M-estimator is unique and uses the quadratic-then-linear $\rho$ above, with $k$ depending on $\epsilon$, and that it remains the most robust even among all translation-invariant estimators.[1] The paper also shows that the estimator is the maximum likelihood estimator for a least favorable distribution whose density is proportional to $e^{-\rho(t)}$: normal in the center and exponential in the tails. Huber wrote that he found this surprising, having expected much heavier tails.[1] He described the estimator as closely related, and asymptotically equivalent, to the Winsorized mean, in which the most extreme observations are pulled in rather than discarded.[1]
Huber's book Robust Statistics was published by Wiley in 1981, and a Wiley book of the same title with Elvezio Ronchetti as co-author followed in 2009.[3][4]
Choosing the threshold and the scale
Because $\delta$ is measured in the units of the residual, a good value depends on the scale of the target variable.[16] Huber's regression criterion divides residuals by a scale parameter $\sigma$, so that errors smaller than $M\sigma$ are squared and larger ones count linearly, where $M$ is the shape parameter that sets the amount of robustness.[4] A larger $M$ moves the fit toward least squares, more efficient for normal errors but less robust; a smaller $M$ moves it toward L1 regression.[4] Art Owen's 2006 account of the method notes that $M$ is usually fixed rather than estimated, and that Huber proposed $M = 1.35$ to keep 95% statistical efficiency for normally distributed data while gaining as much robustness as possible.[4]
The scale itself must usually be estimated. Huber's 1981 book gave a way to estimate it jointly with the regression coefficients through a criterion that is jointly convex in both, a construction Owen notes is known in convex analysis as the perspective transformation.[4] scikit-learn's HuberRegressor follows this approach: it minimizes
where $H_\epsilon(z) = z^2$ for $|z| < \epsilon$ and $2\epsilon|z| - \epsilon^2$ otherwise (twice the form given above), and $\alpha$ sets an L2 penalty on the coefficients.[15] The library's default is $\epsilon = 1.35$, which its user guide recommends "to achieve 95% statistical efficiency".[14][15] Because $\sigma$ is fitted, scaling the target up or down does not require a new $\epsilon$.[14] The user guide also says HuberRegressor should be faster than RANSAC and Theil-Sen unless the number of samples is very large, because those methods fit on smaller subsets of the data.[15]
Smooth L1 loss in object detection
Ross Girshick's Fast R-CNN paper (2015) trained the bounding-box regression part of its detector with a loss it called $\text{smooth}_{L_1}$:
summed over the four box coordinates.[7] The paper describes it as a robust L1 loss "that is less sensitive to outliers than the L2 loss" used in the earlier R-CNN and SPPnet detectors, and says that with unbounded regression targets an L2 loss can need careful learning-rate tuning to avoid exploding gradients, a sensitivity the new loss removes.[7] With the threshold at 1 this is exactly the Huber loss with $\delta = 1$. Faster R-CNN (Ren, He, Girshick and Sun, 2015) reused the same loss for the bounding box regression of its region proposal network.[8]
PyTorch provides smooth L1 as a separate class, SmoothL1Loss, with its own threshold beta (default 1.0), and documents how the two losses differ when the threshold is not 1:[5][6]
| Property | HuberLoss (threshold $\delta$) | SmoothL1Loss (threshold $\beta$) |
|---|---|---|
| Small errors ($\lvert d \rvert$ below threshold) | $0.5 d^2$ | $0.5 d^2 / \beta$ |
| Large errors | $\delta(\lvert d \rvert - 0.5\delta)$ | $\lvert d \rvert - 0.5\beta$ |
| Slope of the linear part | $\delta$ | 1 |
| Threshold $\to 0$ | Constant 0 | L1 loss |
| Threshold $\to \infty$ | Half the MSE loss | Constant 0 |
| Equal when | threshold = 1 | threshold = 1 |
In general smooth L1 equals the Huber loss divided by the threshold, so the two names describe the same shape with a different scaling.[6]
Use in deep reinforcement learning
The deep Q-network (DQN) of Mnih and colleagues, published in Nature in 2015, trains a neural network to predict action values in Q-learning. The paper's methods section reports that the authors clipped the error term of the update to lie between -1 and 1, and explains that because the absolute value function has derivative -1 for negative inputs and 1 for positive ones, this clipping "corresponds to using an absolute value loss function for errors outside of the (-1,1) interval". It adds that this error clipping further improved the algorithm's stability.[9] Since the gradient of the Huber loss is the clipped residual, this procedure gives the same gradients as a Huber loss with $\delta = 1$ applied to the temporal-difference error.
Later open implementations of DQN write the loss explicitly. Stable-Baselines3's DQN computes F.smooth_l1_loss between the predicted and target Q-values under the comment "Compute Huber loss (less sensitive to outliers)".[10] The official PyTorch DQN tutorial uses nn.SmoothL1Loss and explains that the Huber loss acts like mean squared error for small errors and like mean absolute error for large ones, which makes it more robust to outliers "when the estimates of Q are very noisy".[11]
Regression and gradient boosting
Jerome Friedman's 2001 paper introducing gradient boosting machines gave specific algorithms for least-squares, least-absolute-deviation and Huber-M loss functions for regression, and described gradient-boosted regression trees as highly robust and suited to "mining less than clean data".[12] Several libraries expose Huber loss as a training objective:
| Library | Interface | Threshold parameter |
|---|---|---|
| PyTorch | torch.nn.HuberLoss | delta, default 1.0[5] |
| PyTorch | torch.nn.SmoothL1Loss | beta, default 1.0[6] |
| Keras | keras.losses.Huber | delta, default 1.0[18] |
| scikit-learn | HuberRegressor | epsilon, default 1.35, with fitted scale[14] |
| scikit-learn | SGDRegressor(loss="huber") | epsilon, in target units[16] |
| scikit-learn | GradientBoostingRegressor(loss="huber") | alpha, default 0.9 (a quantile)[13] |
| LightGBM | objective="huber" | alpha, default 0.9[17] |
| XGBoost | objective="reg:pseudohubererror" (pseudo-Huber) | huber_slope, default 1.0[19] |
In scikit-learn's gradient boosting the Huber threshold is not given directly: the alpha parameter is documented as "the alpha-quantile of the huber loss function".[13] For SGDRegressor, the documentation notes that the Huber threshold depends on the scale of the target variable.[16]
Comparison with other regression losses
| Loss | Per-example formula | Location estimate it yields | Growth for large errors | Smooth at zero |
|---|---|---|---|---|
| Squared loss | $a^2$ | Mean[1] | Quadratic | Yes |
| Absolute (L1) loss | $\lvert a \rvert$ | Median[1] | Linear | No |
| Huber loss | $\frac{1}{2}a^2$, then $\delta(\lvert a \rvert - \frac{1}{2}\delta)$ | Between mean and median[1] | Linear | Yes |
Huber described his estimators as "intermediaries between sample mean and sample median".[1] scikit-learn's user guide makes the practical contrast with RANSAC and Theil-Sen regression: Huber regression does not ignore the effect of outliers but gives them less weight.[15]
Variants
Pseudo-Huber loss
The pseudo-Huber loss replaces the piecewise definition with one smooth formula, $\sqrt{a^2 + c^2} - c$ for a constant $c > 0$, which is near-quadratic for small residuals and near-linear for large ones and is twice continuously differentiable.[21] Jonathan Barron's "A General and Adaptive Robust Loss Function" notes that the same function (in the scaled form $\sqrt{(x/c)^2 + 1} - 1$) is often called the Charbonnier loss, the pseudo-Huber loss "as it resembles Huber loss", or the L1-L2 loss, and includes it as one member of a two-parameter family of robust losses.[20] XGBoost offers it as reg:pseudohubererror, which its documentation calls "a twice differentiable alternative to absolute loss".[19]
The variant has found use in generative modeling. In "Improved Techniques for Training Consistency Models" (2023), Yang Song and Prafulla Dhariwal adopted pseudo-Huber metrics in place of the learned LPIPS metric when training consistency models, reporting that they gave notably better sample quality than squared L2 on CIFAR-10 and reduced the variance of parameter updates during training.[21] A 2024 paper by Khrapov and colleagues proposed a pseudo-Huber loss with a time-dependent parameter for diffusion models, aimed at making training robust to outliers and corrupted data in image and audio datasets.[22]
Reversed Huber (berhu) penalty
Owen's 2006 report turned Huber's function around to build a regularization penalty, which he called "Berhu": absolute value for small coefficients and quadratic for large ones. Used as a penalty on regression coefficients, it sets some coefficients exactly to zero as the lasso does, while shrinking large coefficients the way ridge regression does. Owen combined it with a Huber loss on the residuals, each with its own scale parameter, in a single jointly convex objective.[4]
Modified Huber loss for classification
scikit-learn's stochastic gradient descent classifier offers a modified_huber loss, described as a "smoothed hinge loss": $\max(0, 1 - y f(x))^2$ when the margin $y f(x)$ exceeds -1, and $-4 y f(x)$ otherwise. Unlike the plain hinge loss, it lets the classifier produce probability estimates.[16]
Continue reading
- Loss FunctionA loss function assigns a numerical cost to a prediction, decision, or action after an outcome is observed.Mentioned twice above
- Squared LossSquared loss, also called quadratic loss, L2 loss, or squared error loss, is a loss function that penalizes a prediction by the square of its error: for a true value $y$ and a prediction $\hat{y}$Listed in See also
- OutliersAn outlier is a data point that differs so markedly from the rest of a dataset that it appears not to belong to the same population.Listed in See also
- Mean Absolute Error (MAE)Mean Absolute Error (MAE) is a regression accuracy metric and loss function that measures the average absolute difference between predicted values and actual observed valuesListed in See also
- Mean Squared Error (MSE)Mean Squared Error (MSE), also called mean squared deviation (MSD), is the average of the squared differences between predicted values and actual (observed) values.Listed in See also
- Quantile regressionQuantile regression is a family of statistical and machine learning methods that estimate conditional quantiles of a response variable, such as its median or its 10th and 90th percentiles given a set of…Listed in See also
More from See also
More to read
Topics:Deep LearningMachine LearningStatisticsTraining & Optimization
References
- ^1 ^2 ^3 ^4 ^5 ^6 ^7 ^8 ^9 ^10 ^11 ^12 ^13 ^14 ^15Huber, Peter J. "Robust Estimation of a Location Parameter". The Annals of Mathematical Statistics, 35(1): 73-101, March 1964. doi.org/...1177703732
- ^1 ^2Buja, Andreas; Künsch, Hans R. "A Conversation with Peter Huber". Statistical Science, 23(1): 120-135, 2008. arxiv.org/...0808.0777
- ^Huber, Peter J.; Ronchetti, Elvezio M. "Robust Statistics". Wiley, 2009. doi.org/...9780470434697
- ^1 ^2 ^3 ^4 ^5 ^6Owen, Art B. "A robust hybrid of lasso and ridge regression". Stanford University, October 2006. artowen.su.domains/...hhu.pdf
- ^1 ^2 ^3 ^4 ^5 ^6PyTorch. "HuberLoss". PyTorch documentation, 2026. docs.pytorch.org/...torch.nn.HuberLoss
- ^1 ^2 ^3 ^4PyTorch. "SmoothL1Loss". PyTorch documentation, 2026. docs.pytorch.org/...torch.nn.SmoothL1Loss
- ^1 ^2 ^3Girshick, Ross. "Fast R-CNN". arXiv:1504.08083, April 2015. arxiv.org/...1504.08083
- ^Ren, Shaoqing; He, Kaiming; Girshick, Ross; Sun, Jian. "Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks". arXiv:1506.01497, 2015. arxiv.org/...1506.01497
- ^1 ^2Mnih, Volodymyr; Kavukcuoglu, Koray; Silver, David; et al. "Human-level control through deep reinforcement learning". Nature, 518: 529-533, February 2015. doi.org/...nature14236
- ^1 ^2DLR-RM. "stable_baselines3/dqn/dqn.py". Stable-Baselines3, GitHub. github.com/...dqn.py
- ^1 ^2Paszke, Adam; Towers, Mark. "Reinforcement Learning (DQN) Tutorial". PyTorch Tutorials. docs.pytorch.org/...reinforcement_q_learning
- ^1 ^2Friedman, Jerome H. "Greedy function approximation: A gradient boosting machine". The Annals of Statistics, 29(5): 1189-1232, October 2001. doi.org/...1013203451
- ^1 ^2scikit-learn developers. "GradientBoostingRegressor". scikit-learn documentation, 2026. scikit-learn.org/...mble.GradientBoostingRegressor
- ^1 ^2 ^3 ^4scikit-learn developers. "HuberRegressor". scikit-learn 1.9.1 documentation, 2026. scikit-learn.org/...rn.linear_model.HuberRegressor
- ^1 ^2 ^3 ^4scikit-learn developers. "Linear Models: Huber Regression". scikit-learn User Guide, 2026. scikit-learn.org/...linear_model
- ^1 ^2 ^3 ^4scikit-learn developers. "Stochastic Gradient Descent". scikit-learn User Guide, 2026. scikit-learn.org/...sgd
- ^LightGBM developers. "Parameters". LightGBM documentation, 2026. lightgbm.readthedocs.io/...Parameters
- ^1 ^2 ^3Keras. "Regression losses". Keras API documentation, 2026. keras.io/...regression_losses
- ^1 ^2 ^3XGBoost developers. "XGBoost Parameters". XGBoost documentation, 2026. xgboost.readthedocs.io/...parameter
- ^Barron, Jonathan T. "A General and Adaptive Robust Loss Function". arXiv:1701.03077, 2017 (revised April 2019). arxiv.org/...1701.03077
- ^1 ^2 ^3Song, Yang; Dhariwal, Prafulla. "Improved Techniques for Training Consistency Models". arXiv:2310.14189, October 2023. arxiv.org/...2310.14189
- ^Khrapov, Artem; Popov, Vadim; Sadekova, Tasnima; Yermekova, Assel; Kudinov, Mikhail. "Improving Diffusion Models's Data-Corruption Resistance using Scheduled Pseudo-Huber Loss". arXiv:2403.16728, March 2024. arxiv.org/...2403.16728
Improve this article
Add missing citations, update stale details, or write a clearer explanation. Anyone can edit: changes go live when you publish, and every edit is checked by an editor.
2 revisions · v2 · 2,732 words · full history
Fact-checks are independent of edits: a reviewer re-verifies the article against its sources and stamps the date. How we verify
Research and drafting on this wiki are AI-assisted, under named human editorial standards. How AI is used here
Reviewer note: Independent fact-check before publication on November 18, 2026: 64 claims checked against 23 cited and independent sources; 0 material and 3 minor corrections applied before publication.
Cite this page: AI Wiki. "Huber loss." aiwiki.ai, updated 18 Nov 2026, fact-checked 18 Nov 2026. CC BY 4.0. https://aiwiki.ai/wiki/huber_loss



