All problems
Hinge Loss
Problem
Compute the mean hinge loss for labels in {-1, +1}: (1/n) * sum(max(0, 1 - y_i * score_i)).
Empty input returns 0.0.
Hint
A sample is penalized only when its margin y*score is less than one.
Test cases
case 1
in: [[1,-1],[0.5,0.5]]
expected: 1
case 2
in: [[1,1],[2,3]]
expected: 0
case 3
in: [[1,-1],[-1,-2]]
expected: 1
case 4
in: [[],[]]
expected: 0
Starter codePython
def hinge_loss(y_true, scores):
# Your code here
pass4 test cases · run your code against them in the editor