liveBook · Manning

Class imbalance

As explained in Statistics Every Programmer Needs

Class imbalance is a condition in which classes in a labeled dataset have substantially unequal representation.

Class imbalance occurs when labeled classes have substantially unequal representation. Models may favor the majority class and underperform on the minority class. section 6.3.4

Overall accuracy can hide this problem. Evaluate predictions separately by class with a confusion matrix and class-specific accuracy rates. section 6.3.4 section 6.4.3

Unequal performance across conversion outcomes

A decision tree predicting successful and unsuccessful fourth-down conversions achieved 51% accuracy when the true label was 0 but 72% when it was 1. The disparity may reflect imbalanced data or different feature patterns. section 6.3.4

>>> from sklearn.metrics import confusion_matrix,
>>> conf_matrix = confusion_matrix(y_test, y_pred)
>>> print(conf_matrix)
[[71 67]
 [36 91]]

Inspect the confusion matrix before relying on overall accuracy; its cells support separate evaluation of each class. section 6.3.4

How Statistics Every Programmer Needs covers it

How deep it goes
Defines majority-class bias and demonstrates class-specific accuracy, but stops short of prescribing imbalance remedies.
Examples
Uses fourth-down conversion predictions, confusion matrices, and separate accuracy calculations for labels 0 and 1.
What it assumes
Assumes labeled classification data and basic familiarity with predictions, true labels, and confusion-matrix cells.
What you can do after
Evaluate classification performance by class using confusion matrices and class-specific accuracy calculations.
How it connects
Connects class imbalance to majority class, minority class, confusion matrix, accuracy, decision trees, and random forests.

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 Statistics Every Programmer Needs. The section links point to the parts of the book it draws on.