Compute binary hinge loss from labels in {−1,+1} and real-valued prediction scores:
ℓi=max(0,m−yisi)Here, yi is the label, si is its prediction score, m is the margin, and ℓi is the sample loss. Return the mean of the sample losses when reduction="mean" or their sum when reduction="sum". The result must be a Python float.
Input: y_true = [1, 1, -1], y_score = [2, 0, 0], margin = 1.0, reduction = "mean"
Output: 0.666667
Explanation: The sample losses are [0, 1, 1], whose mean is 2/3.
Input: y_true = [-1, 1], y_score = [-3, 0.5], margin = 1.0, reduction = "mean"
Output: 0.25
Use np.maximum(0.0, margin - y_true * y_score) to compute all sample losses.
Finish with .mean() or .sum() according to reduction.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: string
Compute binary hinge loss from labels in {−1,+1} and real-valued prediction scores:
ℓi=max(0,m−yisi)Here, yi is the label, si is its prediction score, m is the margin, and ℓi is the sample loss. Return the mean of the sample losses when reduction="mean" or their sum when reduction="sum". The result must be a Python float.
Input: y_true = [1, 1, -1], y_score = [2, 0, 0], margin = 1.0, reduction = "mean"
Output: 0.666667
Explanation: The sample losses are [0, 1, 1], whose mean is 2/3.
Input: y_true = [-1, 1], y_score = [-3, 0.5], margin = 1.0, reduction = "mean"
Output: 0.25
Use np.maximum(0.0, margin - y_true * y_score) to compute all sample losses.
Finish with .mean() or .sum() according to reduction.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: string