How do you handle class imbalance in a dataset?
mediumAnswer
- Options: (1) resampling — oversample minority (SMOTE) or undersample majority; (2) class weights in the loss function; (3) threshold tuning on the probability output; (4) anomaly-detection framing when positives are extremely rare; (5) collect more minority data.
- Always evaluate with PR-AUC, F1 or recall at fixed precision — not plain accuracy.
Check yourself — multiple choice
- Always oversample the majority class
- Use accuracy as the main metric
- Use class weights, resampling (SMOTE) or threshold tuning
- Drop the minority class
Class weights, SMOTE-style resampling, and threshold tuning are the standard remedies.
#imbalance#data-quality
Practise Supervised Learning
215 interview questions in this topic.
Related questions
- When should you use PR-AUC instead of ROC-AUC?
- What is target leakage and how do you prevent it?
- Why is the base rate of the positive class critical to know?
- How do class weights work in logistic regression, and when do you use them?
- You trained Naive Bayes on balanced data but deploy on data where positives are 1%. What happens and what do you do?
- How do you handle class imbalance in XGBoost / LightGBM?