Understanding Class Imbalance
What you'll learn: You'll learn what class imbalance is, how to measure its severity, and why accuracy becomes a misleading metric when classes are imbalanced.
What is Class Imbalance?
Class imbalance occurs when the distribution of examples across different classes is severely unequal. Imagine a fraud detection system where 99.5% of transactions are legitimate and only 0.5% are fraudulent. This is a classic imbalanced dataset—one class (legitimate) vastly outnumbers the other (fraud).
Severity Levels
Class imbalance exists on a spectrum:
- Mild imbalance: 60:40 or 70:30 ratio (often manageable with standard methods)
- Moderate imbalance: 90:10 or 95:5 ratio (requires careful attention)
- Severe imbalance: 99:1 or 999:1 ratio (demands specialized techniques)
The imbalance ratio (majority class / minority class) quantifies severity. A 100:1 ratio means the majority class has 100 times more examples than the minority.
Why Accuracy Fails
Standard accuracy becomes meaningless in imbalanced settings. In our fraud example, a model that blindly predicts "legitimate" for every transaction achieves 99.5% accuracy—but catches zero fraud cases!
This is the accuracy paradox: a model can have excellent accuracy while being completely useless for the actual problem you're trying to solve.
You've already learned that metrics like precision, recall, F1 score, and AUC-PR are far more informative than accuracy for imbalanced data. These metrics focus on the minority class performance, which is typically what matters most.
Key Takeaway: Class imbalance makes the minority class underrepresented during training and causes accuracy to become a misleading metric; always evaluate imbalanced problems using precision, recall, F1, or AUC-PR instead.