Huber Loss
MediumMachine LearningMath
Description
Given predictions, targets, and a threshold delta, return the mean Huber loss. For each pair with error e = |prediction - target|, the loss is 0.5 * e^2 when e <= delta and delta * (e - 0.5 * delta) otherwise. Round the result to 4 decimal places.
Examples
Input:
[3,5], [2,2], 1Output:
1.5Explanation:
Small errors are penalized quadratically while large errors switch to a linear penalty, making the loss robust to outliers.
Input:
[2,2], [2,2], 1Output:
0Explanation:
Small errors are penalized quadratically while large errors switch to a linear penalty, making the loss robust to outliers.
Input:
[10], [0], 2Output:
18Explanation:
Small errors are penalized quadratically while large errors switch to a linear penalty, making the loss robust to outliers.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
delta > 0