Skip to content
DeepForgeby svx
All problems
EasyCalculusca-283

Huber Loss Gradient

Problem

For residuals r = pred - target, the Huber loss uses gradient r when |r| <= delta and delta * sign(r) otherwise.

Given predictions, targets, and delta, return the gradient list.

Hint

Huber is quadratic near zero and linear outside the delta band.

Test cases

case 1
in: [[1,5],[2,2]]
expected: [-1,1]
case 2
in: [[1.5,1.5],[0,3],1]
expected: [1,-1]
case 3
in: [[3,-3],[0,0],2]
expected: [2,-2]
Starter codePython
def huber_gradient(preds, targets, delta=1.0):
    # Your code here
    pass

3 test cases · run your code against them in the editor