Class imbalance occurs when classes contain substantially different numbers of examples. A classifier can then achieve high accuracy while overlooking the minority class, so evaluation and training should reflect the real cost of errors. section 5.4.3 section 9.3.1
Handle the condition by aligning model behavior and evaluation with the important errors:
- Measure balanced accuracy when class frequencies are skewed, weighting predictions by class size rather than allowing the majority class to dominate. section 9.3.1
- Use recall when false negatives are costly, such as missing customers likely to subscribe or missing medical diagnoses. section 5.4.3 section 9.3.1
- Use precision when false positives are costly, such as incorrectly flagging messages as spam. section 5.4.3
- Tailor the loss when standard cross-entropy does not express the task’s priorities; focal loss emphasizes harder examples and downplays easy ones. section 5.4.3
Bank marketing prediction
Only 10% of customers subscribed to a fixed-term deposit, creating a strongly imbalanced target. Stratified splitting preserves the class ratio, while balanced accuracy and recall provide more informative evaluation than ordinary accuracy alone. Removing the post-call duration feature also avoids target leakage in a deployable model. section 9.2.1 section 9.3.1
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.
Visualizes how increasing focal-loss gamma shifts emphasis away from well-classified examples and toward difficult cases. section 5.4.3










