loss_function_hubber


Loss function: Smooth Mean Absolute Error or Hubber Loss.

smae = loss_function_hubber(y_true, y_pred, delta)

Input variables

Name Description Type
y_true True values List
y_pred Predicted values List
delta Threshold Float

Output variables

Name Description Type
hubber Smooth Mean Absolute Error or Hubber Loss Float

Problem

\[f(\mathbf{y}_{\text{true}}, \mathbf{y}_{\text{pred}}) = \frac{1}{n} \cdot \sum_{i=1}^{n} L_\delta(y_{\text{true},i}, y_{\text{pred},i})\]

(1)

\[L_\delta(a, b) = \begin{cases} 0.5 \cdot (a-b)^2 & \text{for } |a-b| \leq \delta, \\ \delta \cdot |a-b| - 0.5 \cdot \delta^2 & \text{otherwise.} \end{cases}\]

(2)

\[a=y_{\text{true},i} \;\; b=y_{\text{pred},i}\]

(3)

\(n\) is the number of samples.

Example 1

Considering the true values \(\mathbf{y}_{\text{true}} = [1.0, 2.0, 3.0, 4.0, 5.0]\), predicted values \(\mathbf{y}_{\text{pred}} = [1.2, 2.3, 2.9, 4.2, 5.3]\), and a threshold \(\mathbf{\delta = 0.5}\), what is the resulting Hubber Loss?

# Data
y_true_example = [1.0, 2.0, 3.0, 4.0, 5.0]
y_pred_example = [1.2, 2.3, 2.9, 4.2, 5.3]
delta_example = 0.5

# Call the loss function
hubber_loss_value = loss_function_hubber(y_true_example, y_pred_example, delta_example)

# Print the result
print("Hubber Loss: {:.4f}".format(hubber_loss_value))
Hubber Loss: 0.1350