# Huber loss

> Source: https://aiwiki.ai/wiki/huber_loss
> Updated: 2026-11-18
> Fact-checked: 2026-11-18
> Categories: Deep Learning, Machine Learning, Statistics, Training & Optimization
> License: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/) - attribute to "AI Wiki (aiwiki.ai)"
> Cite as: AI Wiki. "Huber loss." aiwiki.ai, 18 Nov 2026. https://aiwiki.ai/wiki/huber_loss
> From AI Wiki (https://aiwiki.ai), the free encyclopedia of artificial intelligence. Reuse freely with attribution.

**Huber loss** is a [loss function](https://aiwiki.ai/wiki/loss_function) for [regression](https://aiwiki.ai/wiki/regression) that is quadratic for small errors and linear for large ones, so it behaves like [squared loss](https://aiwiki.ai/wiki/squared_loss) near zero and like absolute loss ([L1 loss](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/gradient_boosting), and in deep learning both directly and in a rescaled form called smooth L1 loss, which the Fast R-CNN [object detection](https://aiwiki.ai/wiki/object_detection) network introduced for bounding-box regression.[7][12][14] Clipping the error term in [DeepMind](https://aiwiki.ai/wiki/google_deepmind)'s 2015 deep Q-network gives the same gradients as using it, and later DQN implementations apply it explicitly.[9][10][11]

<figure>
<img src="/images/media-2026-11-18-huber_loss-895b40a74944.png" alt="Plot from -4 to 4: a blue parabola reaching 8 and a green curve that matches it near 0 then rises linearly to 3.5" width="1200" height="900" />
<figcaption>Huber loss (green) compared with squared error loss (blue) as a function of the residual. Qwertyus, via <a href="https://commons.wikimedia.org/wiki/File:Huber_loss.svg">Wikimedia Commons</a>, <a href="https://creativecommons.org/licenses/by-sa/4.0">CC BY-SA 4.0</a>.</figcaption>
</figure>

## 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

$$
L_\delta(a) =
\begin{cases}
\frac{1}{2} a^2 & \text{if } |a| \le \delta, \\
\delta \left( |a| - \frac{1}{2}\delta \right) & \text{otherwise.}
\end{cases}
$$

This is the form used by [PyTorch](https://aiwiki.ai/wiki/pytorch)'s `HuberLoss` and [Keras](https://aiwiki.ai/wiki/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]$:

$$
\psi_\delta(a) = \frac{dL_\delta}{da} = \max(-\delta, \min(\delta, a)).
$$

Inside the threshold the gradient grows in proportion to the error, as it does for [mean squared error](https://aiwiki.ai/wiki/mean_squared_error_mse); outside, its magnitude is fixed at $\delta$, as for [mean absolute error](https://aiwiki.ai/wiki/mean_absolute_error_mae), 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](https://aiwiki.ai/wiki/maximum_likelihood_estimation) 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](https://aiwiki.ai/wiki/scikit_learn)'s `HuberRegressor` follows this approach: it minimizes

$$
\min_{w, \sigma} \sum_{i=1}^{n} \left( \sigma + H_\epsilon\!\left( \frac{X_i w - y_i}{\sigma} \right) \sigma \right) + \alpha \lVert w \rVert_2^2,
$$

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}$:

$$
\text{smooth}_{L_1}(x) =
\begin{cases}
0.5 x^2 & \text{if } |x| < 1, \\
|x| - 0.5 & \text{otherwise,}
\end{cases}
$$

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](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/exploding_gradient_problem), a sensitivity the new loss removes.[7] With the threshold at 1 this is exactly the Huber loss with $\delta = 1$. [Faster R-CNN](https://aiwiki.ai/wiki/faster_r_cnn) (Ren, He, Girshick and Sun, 2015) reused the same loss for the [bounding box](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/diffusion_model), 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](https://aiwiki.ai/wiki/lasso_regression) does, while shrinking large coefficients the way [ridge regression](https://aiwiki.ai/wiki/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](https://aiwiki.ai/wiki/hinge_loss), it lets the classifier produce probability estimates.[16]

## See also

- [Loss function](https://aiwiki.ai/wiki/loss_function)
- [Squared loss](https://aiwiki.ai/wiki/squared_loss)
- [Mean absolute error](https://aiwiki.ai/wiki/mean_absolute_error_mae)
- [Mean squared error](https://aiwiki.ai/wiki/mean_squared_error_mse)
- [Outliers](https://aiwiki.ai/wiki/outliers)
- [Quantile regression](https://aiwiki.ai/wiki/quantile_regression)
- [Gradient clipping](https://aiwiki.ai/wiki/gradient_clipping)

## References

1. Huber, Peter J. "Robust Estimation of a Location Parameter". The Annals of Mathematical Statistics, 35(1): 73-101, March 1964. https://doi.org/10.1214/aoms/1177703732
2. Buja, Andreas; Künsch, Hans R. "A Conversation with Peter Huber". Statistical Science, 23(1): 120-135, 2008. https://arxiv.org/abs/0808.0777
3. Huber, Peter J.; Ronchetti, Elvezio M. "Robust Statistics". Wiley, 2009. https://doi.org/10.1002/9780470434697
4. Owen, Art B. "A robust hybrid of lasso and ridge regression". Stanford University, October 2006. https://artowen.su.domains/reports/hhu.pdf
5. PyTorch. "HuberLoss". PyTorch documentation, 2026. https://docs.pytorch.org/docs/stable/generated/torch.nn.HuberLoss.html
6. PyTorch. "SmoothL1Loss". PyTorch documentation, 2026. https://docs.pytorch.org/docs/stable/generated/torch.nn.SmoothL1Loss.html
7. Girshick, Ross. "Fast R-CNN". arXiv:1504.08083, April 2015. https://arxiv.org/abs/1504.08083
8. Ren, Shaoqing; He, Kaiming; Girshick, Ross; Sun, Jian. "Faster R-CNN: Towards Real-Time Object Detection with Region Proposal Networks". arXiv:1506.01497, 2015. https://arxiv.org/abs/1506.01497
9. Mnih, Volodymyr; Kavukcuoglu, Koray; Silver, David; et al. "Human-level control through deep reinforcement learning". Nature, 518: 529-533, February 2015. https://doi.org/10.1038/nature14236
10. DLR-RM. "stable_baselines3/dqn/dqn.py". Stable-Baselines3, GitHub. https://github.com/DLR-RM/stable-baselines3/blob/master/stable_baselines3/dqn/dqn.py
11. Paszke, Adam; Towers, Mark. "Reinforcement Learning (DQN) Tutorial". PyTorch Tutorials. https://docs.pytorch.org/tutorials/intermediate/reinforcement_q_learning.html
12. Friedman, Jerome H. "Greedy function approximation: A gradient boosting machine". The Annals of Statistics, 29(5): 1189-1232, October 2001. https://doi.org/10.1214/aos/1013203451
13. scikit-learn developers. "GradientBoostingRegressor". scikit-learn documentation, 2026. https://scikit-learn.org/stable/modules/generated/sklearn.ensemble.GradientBoostingRegressor.html
14. scikit-learn developers. "HuberRegressor". scikit-learn 1.9.1 documentation, 2026. https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.HuberRegressor.html
15. scikit-learn developers. "Linear Models: Huber Regression". scikit-learn User Guide, 2026. https://scikit-learn.org/stable/modules/linear_model.html
16. scikit-learn developers. "Stochastic Gradient Descent". scikit-learn User Guide, 2026. https://scikit-learn.org/stable/modules/sgd.html
17. LightGBM developers. "Parameters". LightGBM documentation, 2026. https://lightgbm.readthedocs.io/en/latest/Parameters.html
18. Keras. "Regression losses". Keras API documentation, 2026. https://keras.io/api/losses/regression_losses/
19. XGBoost developers. "XGBoost Parameters". XGBoost documentation, 2026. https://xgboost.readthedocs.io/en/stable/parameter.html
20. Barron, Jonathan T. "A General and Adaptive Robust Loss Function". arXiv:1701.03077, 2017 (revised April 2019). https://arxiv.org/abs/1701.03077
21. Song, Yang; Dhariwal, Prafulla. "Improved Techniques for Training Consistency Models". arXiv:2310.14189, October 2023. https://arxiv.org/abs/2310.14189
22. 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. https://arxiv.org/abs/2403.16728

