Imbalanced Data: SMOTE, Class Weights and Sampling
Imbalanced datasets are common in fraud detection, medical diagnosis, and anomaly detection. This lesson covers techniques to handle class imbalance.
The Imbalanced Data Problem
Resampling Techniques
SMOTE Algorithm
The SMOTE formula generates a synthetic sample along the line between a minority sample and one of its nearest neighbors:
Class Weights
Class weights adjust the loss function to penalize minority class misclassifications more heavily:
where is total samples, is samples in class , and is the number of classes.
Evaluation Metrics
Key metrics for imbalanced data:
Threshold Optimization
Ensemble Methods for Imbalanced Data
Key Takeaways
- Never use accuracy alone for imbalanced problems
- Use SMOTE or class weights as first approaches
- Optimize decision threshold for your cost function
- Consider ensemble methods like BalancedRandomForest
- Always evaluate with AUPRC for severely imbalanced data