Compute the mean binary focal loss from predicted probabilities:
Li=−(1−pi)γyilog(pi)−piγ(1−yi)log(1−pi)Here, pi is the predicted probability for sample i, yi is its binary label, and γ is gamma. Clip probabilities only for numerical stability, then return the mean of all Li values as a Python float.
Input: p = [0.9, 0.2, 0.7, 0.1], y = [1, 0, 1, 0], gamma = 2.0
Output: 0.010783
Explanation: Confident correct predictions receive small weights, so their mean focal loss is low.
Input: p = [0.5, 0.5, 0.5, 0.5], y = [1, 0, 1, 0], gamma = 2.0
Output: 0.173287
Input: p = [0.9, 0.2, 0.7, 0.1], y = [1, 0, 1, 0], gamma = 0.0
Output: 0.197635
Use np.clip(p, 1e-15, 1.0 - 1e-15) before taking logarithms.
Use np.log1p(-p) for the negative-class logarithm.
Average the negative sum of the positive and negative terms.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Compute the mean binary focal loss from predicted probabilities:
Li=−(1−pi)γyilog(pi)−piγ(1−yi)log(1−pi)Here, pi is the predicted probability for sample i, yi is its binary label, and γ is gamma. Clip probabilities only for numerical stability, then return the mean of all Li values as a Python float.
Input: p = [0.9, 0.2, 0.7, 0.1], y = [1, 0, 1, 0], gamma = 2.0
Output: 0.010783
Explanation: Confident correct predictions receive small weights, so their mean focal loss is low.
Input: p = [0.5, 0.5, 0.5, 0.5], y = [1, 0, 1, 0], gamma = 2.0
Output: 0.173287
Input: p = [0.9, 0.2, 0.7, 0.1], y = [1, 0, 1, 0], gamma = 0.0
Output: 0.197635
Use np.clip(p, 1e-15, 1.0 - 1e-15) before taking logarithms.
Use np.log1p(-p) for the negative-class logarithm.
Average the negative sum of the positive and negative terms.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number