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
Real-World Imbalanced Problems
Why Standard ML Fails
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
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