What is class imbalance?
Class imbalance describes a dataset where the classes are represented very unequally, for example thousands of images of common objects and only a handful of a rare one. Because a model minimizes overall error, it is tempted to do well on the majority and neglect the minority, which is often exactly the class you care about.
This is dangerous because a metric like accuracy can look excellent while the model essentially ignores rare classes.
Key takeaways
- Imbalance means some classes vastly outnumber others.
- Models tend to favor majority classes and miss rare ones.
- Accuracy can hide the problem, so use per-class metrics.
How it works
The imbalance biases the learning signal toward frequent classes. Common remedies include resampling the data by oversampling rare classes or undersampling common ones, reweighting the loss to penalize minority errors more, and augmenting or synthesizing examples of rare classes. Evaluation should rely on per-class metrics and F1 rather than overall accuracy.
Why it matters
Real-world datasets are almost always imbalanced, and the rare classes are frequently the high-stakes ones, such as defects or hazards. Diagnosing and addressing imbalance is a core curation task, closely tied to investigating the long tail of a dataset.
Frequently asked questions
Why is accuracy misleading under class imbalance?
A model can score high accuracy by predicting the majority class and ignoring rare ones, so per-class metrics and F1 give a truer picture.
How do you fix class imbalance?
Through resampling, loss reweighting, and augmenting or synthesizing rare-class examples, chosen based on the task and how rare the classes are.
Related terms