Data Scientist interview question
How do you handle class imbalance?
Use metrics such as precision-recall and cost-weighted error rather than accuracy, keep validation prevalence realistic, tune the decision threshold, and consider class weights or resampling only inside training folds.
Direct answer
What a strong answer covers
How it works
When positives are rare, accuracy rewards a model that predicts the majority class every time, so evaluation switches to precision, recall, the precision-recall curve, and a cost-weighted metric that reflects what a false positive and a false negative each cost. The validation set keeps the real prevalence so numbers transfer to production. Most models output a score; choosing the decision threshold for the business cost usually matters more than resampling. Class weights or oversampling can help training, but only applied inside the training fold, never to validation data, and calibration is checked afterwards because resampling distorts probabilities.
Example
A fraud model on 0.5 percent positives reported 99.5 percent accuracy by flagging nothing. Switching to precision-recall showed the useful operating region; setting the threshold so that the review team’s capacity of 200 cases per day was filled with the highest-risk transactions caught 62 percent of fraud at 35 percent precision, and calibration was restored with isotonic regression after training with class weights.
Common mistakes
- Reporting accuracy or ROC AUC alone on a heavily skewed problem.
- Oversampling before the split so duplicates leak into validation.
- Using the default 0.5 threshold and never asking what the errors cost.
A useful answer structure
Answer from your own work.
Do not memorise a script: use only examples you can explain honestly in follow-up questions.
Open the desktop workspace and rehearse a clear answer in your own words.