Skip to main content
Imbalanced Data Concept
Imbalanced Data Real World Example

Handling Imbalanced Data

The 1% Problem

Your fraud detection model has 99.5% accuracy. Amazing, right? Wait. The dataset has:
  • 99.5% legitimate transactions
  • 0.5% fraudulent transactions
Your model predicts “legitimate” for everything. It catches zero fraud. This is the imbalanced data problem - and it’s everywhere in real ML.

Real-World Imbalanced Problems


Why Standard ML Fails

The model learns to predict the majority class almost exclusively!

Evaluation for Imbalanced Data

Don’t Use Accuracy!

The Metrics That Matter

Recall (Sensitivity)

Of all actual positives, how many did we catch? Critical for fraud, disease detection

Precision

Of predictions, how many are correct? Important when false positives are costly

F1 Score

Harmonic mean of precision and recall Good single metric for imbalanced data

PR-AUC

Area under Precision-Recall curve Better than ROC-AUC for imbalanced data

Solution 1: Class Weights

Tell the model that minority class errors matter more:

Solution 2: Resampling

Oversampling (Add Minority Samples)

Undersampling (Remove Majority Samples)

Combination: SMOTE + Tomek

Never resample the test set! Only resample training data. Test data should reflect real-world distribution.

Solution 3: Threshold Tuning

Default threshold is 0.5. For imbalanced data, lower it:

Solution 4: Ensemble Methods for Imbalanced Data

Balanced Random Forest

Easy Ensemble (AdaBoost on balanced subsets)


Comparison: What Works Best?


Real Example: Credit Card Fraud


Decision Flowchart


Key Takeaways

Accuracy Lies

Never use accuracy for imbalanced data

Focus on Recall/F1

These metrics reveal true performance

Resample Wisely

SMOTE for moderate, ensembles for severe imbalance

Tune Thresholds

Lower threshold to catch more minority class

What’s Next?

Learn how to make your models’ decisions understandable with explainability techniques!

Continue to Model Explainability

Understand why your model makes its predictions