# Class Imbalance

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

**Field:** Artificial Intelligence  
**Category:** Machine Learning  
**Also known as:** Imbalanced Data, Imbalanced Dataset, Class Imbalance Problem

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

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

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

## Common mistake

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

## Three principles

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

## Related terms

- [Classification (Machine Learning)](https://learn.benibix.com/term/ai/classification)
- [Recall (Machine Learning)](https://learn.benibix.com/term/ai/recall)
- [Precision (Machine Learning)](https://learn.benibix.com/term/ai/precision)
- [Data Augmentation](https://learn.benibix.com/term/ai/data-augmentation)
- [Anomaly Detection](https://learn.benibix.com/term/ai/anomaly-detection)
- [Confusion Matrix](https://learn.benibix.com/term/ai/confusion-matrix)

## Taught in

- [Data Labeling and Augmentation](https://learn.benibix.com/learn/ai-machine-learning/data-labeling-and-augmentation): Machine Learning, 5/18

![Left panel, class imbalance: 34 grey dots and one highlighted rare dot, with a note that always guessing the common class is 97% right yet never finds the rare one. Right panel, data augmentation: one apple photo becomes four copies, flipped, turned, cropped and darker, all with the same label.](https://learn.benibix.com/diagrams/ai3-imbalance-augment.svg)

---

Source: https://learn.benibix.com/term/ai/class-imbalance
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-17
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
