Compute the mean Huber loss between targets and predictions. For error e=ytrue−ypred:
Lδ(e)={21e2,δ(∣e∣−21δ),∣e∣≤δ∣e∣>δHere, δ is delta. Apply the piecewise loss elementwise and return its mean as a Python float.
Input: y_true = [1, 2, 3], y_pred = [1.5, 1.7, 2.5], delta = 1.0
Output: 0.098333
Explanation: Every absolute error is at most 1, so all three terms use the quadratic branch before averaging.
Input: y_true = [0, 5], y_pred = [2, 8], delta = 1.0
Output: 2.0
Input: y_true = [1, 2], y_pred = [1, 2], delta = 1.0
Output: 0.0
Compute absolute_error = np.abs(y_true - y_pred).
Use np.where to select the two loss branches before taking the mean.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Compute the mean Huber loss between targets and predictions. For error e=ytrue−ypred:
Lδ(e)={21e2,δ(∣e∣−21δ),∣e∣≤δ∣e∣>δHere, δ is delta. Apply the piecewise loss elementwise and return its mean as a Python float.
Input: y_true = [1, 2, 3], y_pred = [1.5, 1.7, 2.5], delta = 1.0
Output: 0.098333
Explanation: Every absolute error is at most 1, so all three terms use the quadratic branch before averaging.
Input: y_true = [0, 5], y_pred = [2, 8], delta = 1.0
Output: 2.0
Input: y_true = [1, 2], y_pred = [1, 2], delta = 1.0
Output: 0.0
Compute absolute_error = np.abs(y_true - y_pred).
Use np.where to select the two loss branches before taking the mean.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number