Hinge Loss
MediumMachine LearningMathArray
Description
Given an array of raw prediction scores and an array of true labels in {-1, +1}, return the mean hinge loss: the average of max(0, 1 - label * score). Round the result to 4 decimal places.
Examples
Input:
[1,1,-1], [1,-1,1]Output:
1.3333Explanation:
Each example is penalized only when its score fails to clear the margin of one on the correct side, and the penalties are averaged.
Input:
[2,2], [1,1]Output:
0Explanation:
Each example is penalized only when its score fails to clear the margin of one on the correct side, and the penalties are averaged.
Input:
[0,0], [1,-1]Output:
1Explanation:
Each example is penalized only when its score fails to clear the margin of one on the correct side, and the penalties are averaged.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
labels are -1 or 1