CLASSICAL ML ยท INTERVIEW QUESTION
How do you handle class imbalance? Compare different approaches.
๐ด advanced ยท Supervised Learning
Hint: Think about data-level, algorithm-level, and evaluation approaches.
Answer
Data-level:
-
Oversampling minority (SMOTE creates synthetic examples along feature space)
-
Undersampling majority (random, Tomek links, NearMiss)
-
Augmentation for minorities. Algorithm-level:
-
Class weights: inverse frequency weighting in loss function.
-
Cost-sensitive learning: different misclassification costs.
-
Focal loss: down-weights easy examples, focuses on hard ones (used in object detection).
-
Consider anomaly detection when useful positive labels are scarce and anomaly assumptions fit. Ensemble:
-
Balanced Random Forest
-
EasyEnsemble (ensemble of undersampled datasets).
Evaluation: use AUPRC, F1, balanced accuracy โ NOT accuracy. Threshold: tune classification threshold based on the PR curve. Best practices: try class weights first (simplest), then SMOTE if needed. No imbalance ratio by itself requires anomaly detection. With useful labels, compare supervised cost-sensitive or ranking models, evaluate at natural deployment prevalence, and set thresholds using costs and review capacity.