Focal loss helps classification models handle severe class imbalance, such as detecting foreground objects among many background windows. It modifies cross-entropy so easy predictions contribute less and difficult predictions receive more attention. section 5.4.3
Its modulating factor is controlled by γ > 0. With γ = 0, focal loss becomes ordinary cross-entropy; increasing γ suppresses well-classified examples more strongly. section 5.4.3
Figure 5.21 The focal loss visualized for various values of γ. When γ = 0, the original cross-entropy loss is recovered. As γ increases, the part of the curve corresponding to well-classified examples becomes longer, reflecting the loss function’s focus on poor classification.
Compare how different γ values reshape the loss and shift emphasis toward poorly classified examples. section 5.4.3
A practical LightGBM implementation follows these steps:
- Convert raw predictions to probabilities with the sigmoid function and compute the focal-loss terms for labels 0 and 1. section 5.4.3
- Return the mean loss as an evaluation metric, then provide numerical first and second derivatives as the custom objective. section 5.4.3
- Train LightGBM with the custom objective, convert raw validation scores to probabilities, and threshold them at 0.5. section 5.4.3


