Home / Machine Learning

Label Imbalance & The Accuracy Paradox

Adjust the class distribution to see why Accuracy is a dangerously misleading metric when dealing with imbalanced datasets like fraud detection or rare diseases.

50%
Dataset Status

PERFECTLY BALANCED

Classes are equal. Accuracy is a reliable and safe metric to use.
Feature Space
Normal (0)
Anomaly (1)
Standard Model Boundary

The "Naive" Model

Predicts ONLY Class 0
Accuracy 0%
Precision (1) N/A
Recall (1) 0%

Standard Trained Model

Logistic Regression
Accuracy 0%
Precision (1) 0%
Recall (1) 0%
What this means:

Waiting for training...

The Accuracy Paradox

In many real-world scenarios, the data we care about is rare. Think of credit card fraud, rare disease detection, or critical system failures. In these datasets, the "normal" class vastly outnumbers the "anomaly" class. This is called Label Imbalance, and it creates a dangerous trap for machine learning models: The Accuracy Paradox.

What is the Accuracy Paradox?

The Accuracy Paradox occurs when a model achieves a very high accuracy score but is completely useless in practice. This happens because the model learns to simply predict the majority class every single time. In a dataset with 99% normal transactions and 1% fraudulent ones, a model that always guesses "normal" will be 99% accurate. It sounds great, but it has failed at its one important job: detecting fraud.

This visualization demonstrates the paradox by comparing two models:

1. The "Naive" Model

This is a deliberately dumb model. Its only rule is: always predict Class 0 (the majority class). It never predicts an anomaly. As you'll see, its accuracy is deceptively high.

2. The Standard Trained Model

This is a standard Logistic Regression model. It tries to learn a decision boundary to separate the two classes based on the data. Watch how its behavior and metrics change as the dataset becomes more imbalanced.

Guided Experiments

Use the interactive panel to build a strong intuition for this problem.

  1. Start with a Balanced Dataset (50%): With the "Class 0 %" slider at 50%, click "Generate & Train". Both classes are equal. The Standard Model learns a reasonable boundary, and its accuracy is a good reflection of its performance. The Naive Model's accuracy is only 50%, correctly showing it's a poor model.
  2. Introduce Moderate Imbalance (85%): Move the slider to 85%. The Naive Model's accuracy instantly jumps to 85%! It's already looking better than the Standard Model, yet it hasn't caught a single anomaly (its Recall is 0%). Notice how the Standard Model's decision boundary starts to shift, becoming more biased towards the majority class. It's getting harder for it to correctly identify anomalies.
  3. Create Severe Imbalance (99%): Push the slider to 99%. The Accuracy Paradox is now in full effect. The Naive Model boasts 99% accuracy, making it look nearly perfect. The Standard Model, overwhelmed by the majority class, gives up trying to find anomalies. Its boundary is pushed far away, and it also classifies everything as Class 0. Its accuracy is also 99%, but its Recall is 0%. Both models are now useless for finding the rare events we care about.

Beyond Accuracy: Why Recall and Precision Matter

The paradox teaches us a critical lesson: accuracy is not the right metric for imbalanced datasets. We need to look at metrics that tell us how well the model performs on the minority class.

  • Recall (Sensitivity): Of all the actual positive cases (anomalies), how many did the model correctly identify? A Recall of 0%, like in our 99% imbalance experiment, means the model is completely blind to the minority class. This is often the most important metric in fraud or disease detection.
  • Precision: Of all the cases the model predicted as positive, how many were actually positive? High precision means the model is trustworthy when it raises an alarm.

When dealing with imbalanced data, always evaluate your model using a Confusion Matrix, and pay close attention to Precision, Recall, and the F1-Score, especially for the rare class you are trying to find.

Cheat sheet

Label Imbalance Problem

In many real-world scenarios, the data we care about is rare. Think of credit card fraud, rare disease detection, or critical system failures. In these datasets, the "normal" class vastly outnumbers the "anomaly" class. This is called Label Imbalance, and it creates a dangerous trap for machine learning models: The Accuracy Paradox.

MACHINE LEARNING · vizlearn.in/machine_learning/label_imbalance_problem.html