Huber loss

Also known as: smooth L1 loss

On this page 7

Huber loss is a robust regression loss function that behaves like squared error for small residuals and like absolute error for large ones, with a threshold parameter delta marking the switch. Training with Huber loss in artificial intelligence and statistics keeps the smooth, well-behaved gradients of mean squared error near the target while preventing outliers from dominating the update.

The loss was introduced by the statistician Peter Huber in 1964 as a tool of robust estimation. In deep learning it appears under the name smooth L1 loss, notably in object detection for bounding box regression and in deep Q-learning, where it stabilizes value updates against occasional large errors.

How Huber loss combines squared and absolute error

For a residual a = y - f(x) and threshold delta, Huber loss equals 0.5 * a^2 when the absolute residual is at most delta, and delta * (|a| - 0.5 * delta) when it is larger. The two pieces meet with the same value and the same slope at the threshold, so the function is continuous and once differentiable everywhere.

The decisive property is the bounded gradient. Inside the quadratic zone the gradient equals the residual itself, so small errors produce proportionally small corrections. Outside it the gradient is fixed at plus or minus delta, so a single wildly wrong label cannot push the parameters with unlimited force, as it would under squared error.

The table below shows how the three classic regression losses treat residuals of different sizes.

ResidualSquared error lossAbsolute error lossHuber lossHuber gradient
0.10.0050.10.0050.1
0.50.1250.50.1250.5
1.00.51.00.51.0
3.04.53.02.51.0
10.050.010.09.51.0
Loss and gradient by residual size, with delta equal to 1

Squared error here is written with the conventional one-half factor, so its values match Huber loss exactly in the quadratic zone.

Choosing the delta threshold

Delta sets the boundary between inliers and outliers, measured in the units of the target variable. A very large delta makes Huber loss practically identical to mean squared error, and a very small delta makes it behave like mean absolute error with a tiny smoothed region around zero.

In classical statistics, a delta of about 1.345 times the noise standard deviation keeps roughly 95 percent of the efficiency of least squares when errors are Gaussian, while still resisting outliers. Deep learning code often uses delta equal to 1 on normalized targets, which is the default in common frameworks.

Delta settingBehaviorTypical use
Very smallClose to absolute errorHeavy-tailed or noisy labels
About 1 on scaled targetsBalanced compromiseDefault for most regression
About 1.345 standard deviationsNear-Gaussian efficiencyStatistical robust regression
Very largeClose to squared errorClean data, few outliers
Effect of the delta setting

Because delta depends on the scale of the target, normalize targets first or set delta relative to their spread. Otherwise the same value can mean nearly pure squared error on one dataset and nearly pure absolute error on another.

Huber loss sits between the two most common regression objectives and has several close relatives. Squared error estimates the conditional mean, absolute error estimates the conditional median, and Huber loss estimates a robust location in between.

LossOutlier sensitivitySmooth at zeroMain drawback
Mean squared errorHighYesOutliers dominate training
Mean absolute errorLowNoConstant gradient slows convergence
Huber lossLow to moderateYesRequires choosing delta
Pseudo-Huber lossLow to moderateYes, all ordersSlightly costlier to compute
Log-cosh lossLow to moderateYes, all ordersNo explicit threshold control
Quantile lossLowNoTargets a quantile, not the center
Regression losses and their trade-offs

Pseudo-Huber loss, defined as delta^2 * (sqrt(1 + (a/delta)^2) - 1), approximates Huber loss with a function that is smooth to every order, which suits second-order optimizers. Smooth L1 loss in frameworks such as PyTorch equals Huber loss divided by its threshold parameter, so the two differ only by a constant scale.

Where Huber loss is used in deep learning

Huber loss is chosen whenever regression targets contain rare large errors that should not dictate the gradient. Its best-known applications are in computer vision and reinforcement learning, but it also appears in forecasting and sensor modeling.

  • Bounding box regression in detectors of the Fast R-CNN family, where coordinate offsets are trained with smooth L1 loss.
  • Deep Q-networks, where clipping the temporal difference error is equivalent to Huber loss and reduces destabilizing updates.
  • Time-series forecasting with spikes, holidays or data-entry errors in the history.
  • Depth and pose estimation, where some ground-truth pixels or keypoints are unreliable.

In gradient boosting libraries, Huber loss is a standard robust objective for regression trees. It is also a practical alternative to aggressive gradient clipping, because it limits the per-sample gradient at the loss level rather than after averaging.

Limitations and common mistakes

Huber loss is not a cure for bad labels. It limits the influence of each outlier but does not remove it, so a large share of systematically wrong targets still biases the model. Its second derivative is discontinuous at the threshold, which matters for Newton-type methods but rarely for stochastic gradient descent.

MistakeSymptomFix
Delta on unscaled targetsLoss acts as pure MSE or MAENormalize targets or scale delta
Confusing smooth L1 and HuberGradients differ by a factorCheck the framework definition
Reporting Huber as accuracyHard-to-interpret metricEvaluate with MAE or RMSE
Using it for classificationPoor probability estimatesUse cross-entropy loss instead
Frequent mistakes when applying Huber loss

A final caution concerns evaluation. Huber loss is mainly a training objective; results should still be reported with interpretable metrics such as mean absolute error or root mean squared error.

In everyday language

A model learns by measuring how wrong it is and correcting itself. Huber loss is one way to measure that error. Small mistakes count strongly, big mistakes count only moderately.

Imagine a teacher grading homework. Most answers are slightly off, so the teacher corrects them carefully. One answer is absurd because of a smudge on the page. A sensible teacher does not rewrite the whole lesson because of that one smudge. Huber loss gives the model the same common sense.

Seen in the real world

A utility company trains a neural network to forecast hourly electricity demand for the next day. Its historical data contains occasional meter failures that record demand as zero or as several times the normal value. With mean squared error, these few corrupted hours produce huge gradients, and the forecasts become erratic around similar times of day.

The data team normalizes demand to unit variance and switches to Huber loss with delta equal to 1. Ordinary forecast errors still receive full quadratic correction, while the corrupted hours contribute only a capped gradient. Training becomes smoother, and mean absolute error on clean validation days drops noticeably.

The team still cleans the worst meter records afterward, because Huber loss reduces but does not remove the effect of bad data.