Loading...
Compute the hinge loss for SVM classification.
Given true labels yi∈{−1,+1} and raw predictions (scores) y^i:
L=n1∑i=1nmax(0,1−yi⋅y^i)
This is the loss function used by Support Vector Machines. Points correctly classified with margin ≥1 contribute zero loss.
Return the average hinge loss rounded to 4 decimal places.
y_true = [1, -1, 1, -1] y_scores = [0.8, -1.2, 0.3, -0.5]
0.35