Reduce sensitivity to outliers
Regression with occasional large residuals.
Keras · Class
Huber is a regression loss that combines squared-error behavior for small errors with absolute-error behavior for large errors. The delta parameter sets the transition between these regions.
Huber computes the error as the difference between targets and predictions. It uses a quadratic penalty when the absolute error is at most delta and a linear penalty for larger errors, then averages the resulting values over the final axis. The loss object can be called directly or supplied to model compilation.
keras.losses.Huber(delta=1.0, reduction="sum_over_batch_size", name="huber_loss", dtype=None)| Name | Type | Description |
|---|---|---|
delta | float | Threshold where the loss changes from quadratic to linear behavior. |
reduction | string | How individual losses are aggregated; the default is sum_over_batch_size. |
name | string | Name assigned to the loss object. |
dtype | string or dtype | Optional data type used by the loss. |
A loss value computed from y_true and y_pred; the documented formula averages the per-element values over the last axis.
import keras
loss_fn = keras.losses.Huber(delta=1.0)
model = keras.Sequential([keras.layers.Dense(1)])
model.compile(optimizer="sgd", loss=loss_fn)
Creates a Huber loss with the default transition point and uses it when compiling a regression model.
Regression with occasional large residuals.
A model compiled with a configurable loss object.
Direct evaluation of target and prediction differences.
Huber is piecewise: for errors whose absolute value is at most delta, it contributes 0.5 times the squared error; for larger errors, it contributes delta times the absolute error minus 0.5 times delta squared. The per-sample values are averaged over the last axis.
Follow-up: What does delta control? It sets the error magnitude at which the quadratic region changes to the linear region.
The constructor defaults delta to 1.0, uses sum_over_batch_size reduction, and names the loss huber_loss. Its callable form accepts true and predicted targets.
Follow-up: How would you configure a different transition point? Instantiate keras.losses.Huber with the desired delta value.
Huber is a regression loss and can be passed as a loss object when compiling a Keras model. The documented constructor is keras.losses.Huber(delta=1.0, reduction="sum_over_batch_size", name="huber_loss", dtype=None).
Follow-up: Why use the class rather than only a function? The class lets you configure constructor arguments such as delta and reduction before calling it.
keras.losses.huberkeras.losses.LogCoshkeras.losses.MeanAbsoluteErrorkeras.losses.MeanSquaredError