What is class imbalance and how do you handle it?

Answer

Class imbalance occurs when one class has significantly more samples than others — common in fraud detection, medical diagnosis, and anomaly detection. Strategies: Resampling — over-sample the minority class (SMOTE creates synthetic examples) or under-sample the majority class. Class weights — give higher loss penalty to minority class mistakes. Threshold tuning — adjust the decision threshold for the positive class. Specialized metrics — use F1, AUC-PR (Precision-Recall AUC), or MCC instead of accuracy. Ensemble methods — BalancedRandomForest, EasyEnsemble.