Binary focal loss addresses the class imbalance problem in binary classification by down-weighting the loss contribution from easy (well-classified) examples. This allows the model to focus training on hard, misclassified examples. It was introduced in the RetinaNet paper for object detection.
Given predicted probabilities, binary targets, a balancing factor alpha, and a focusing parameter gamma, compute the mean binary focal loss.
For each sample, let p be the predicted probability and y be the target (0 or 1):
Return the mean focal loss as a float.
Input: predictions = [0.9], targets = [1], alpha = 1, gamma = 2
Output: 0.001054
Explanation: The factor (1 - 0.9)² strongly reduces the loss of this confident correct prediction.
Input: predictions = [0.1], targets = [1], alpha = 1, gamma = 2
Output: 1.865094
Select p when the target is 1 and one minus p when the target is 0.
Accumulate the focal term with math.log, then divide by the sample count.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: number
Binary focal loss addresses the class imbalance problem in binary classification by down-weighting the loss contribution from easy (well-classified) examples. This allows the model to focus training on hard, misclassified examples. It was introduced in the RetinaNet paper for object detection.
Given predicted probabilities, binary targets, a balancing factor alpha, and a focusing parameter gamma, compute the mean binary focal loss.
For each sample, let p be the predicted probability and y be the target (0 or 1):
Return the mean focal loss as a float.
Input: predictions = [0.9], targets = [1], alpha = 1, gamma = 2
Output: 0.001054
Explanation: The factor (1 - 0.9)² strongly reduces the loss of this confident correct prediction.
Input: predictions = [0.1], targets = [1], alpha = 1, gamma = 2
Output: 1.865094
Select p when the target is 1 and one minus p when the target is 0.
Accumulate the focal term with math.log, then divide by the sample count.
Sign in to take notes on this problem
Accepts: array
Accepts: array
Accepts: number
Accepts: number