Skip to content
BENIBIX Learn

Class Imbalance

Also known as Imbalanced Data, Imbalanced Dataset, Class Imbalance Problem

When one answer is much more rare than the rest in your data.

Think of it like

It is like a bag with 99 red sweets and one blue one. Guess red every time and you are almost always right.

Example

A bank's data holds 50 frauds in 50,000 payments. Jack's first model never flags fraud and still scores 99.9%. Recall shows it finds zero.

Why it matters

The rare case is often the one you care about, like fraud or disease. Imbalance hides it.

Definition

Class imbalance is when one answer is far rarer than the others in your data. Fraud might be 1 in 1,000 payments. A model can then score 99.9% just by always saying "not fraud". That model is useless, because it never finds the rare case. You can fix it by showing the rare case more often, or by making its mistakes cost more. You also judge the model with precision and recall, not accuracy.
The left side shows imbalance: one rare dot among many common ones.

Common mistake

Trusting accuracy when one class is rare. Check precision and recall on that class.

Key takeaways

  1. 1
    One class is rare. Like fraud, or a rare illness.
  2. 2
    Accuracy lies. Always guessing common still scores high.
  3. 3
    Rebalance. Show the rare case more, or weight it.

Learn it properly