liveBook · Manning

Class imbalance

As explained in Ensemble Methods for Machine Learning

Class imbalance is a data-distribution condition in which the classes contain substantially different numbers of examples.

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.
CH05_F21_Kunapuli

Visualizes how increasing focal-loss gamma shifts emphasis away from well-classified examples and toward difficult cases. section 5.4.3

How Ensemble Methods for Machine Learning covers it

How deep it goes
Explains the distributional problem, error tradeoffs, imbalance-aware metrics, and focal-loss implementation with gradient boosting.
Examples
Uses dense object detection, medical diagnosis, spam detection, and Bank Marketing subscription prediction as concrete cases.
What it assumes
Assumes binary classification and basic error terminology while reinforcing precision, recall, accuracy, and false-positive or false-negative tradeoffs.
What you can do after
Apply it via balanced accuracy, recall, stratified splitting, and focal loss to build or evaluate models under skewed class frequencies.
How it connects
Connects class imbalance to precision, recall, balanced accuracy, cross-entropy loss, focal loss, gradient boosting, and target leakage.

Also explained in

Compare how 11 books explain class imbalance →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Ensemble Methods for Machine Learning. The section links point to the parts of the book it draws on.