CLASSICAL ML · INTERVIEW QUESTION
Explain precision, recall, F1-score, and when to use each.
🟡 intermediate · Supervised Learning
Hint: Think about the confusion matrix and different error costs.
Answer
Precision = TP/(TP+FP): of predicted positives, how many are correct? High precision = few false alarms. Recall = TP/(TP+FN): of actual positives, how many did we find? High recall = few misses. F1 = 2·P·R/(P+R): harmonic mean, balances both.
When to use: Precision: when false positives are costly (spam filtering — don't block legit email). Recall: when false negatives are costly (cancer detection — don't miss cases). F1: when you need a single balanced metric. F-beta: F_β = (1+β²)·P·R/(β²·P+R). β>1 weights recall more, β<1 weights precision more.
For imbalanced data: use precision-recall curves and AUPRC instead of ROC/AUC.
Always consider the business cost of each error type.
Related questions
- What is overfitting? How do you detect and prevent it?
- What is cross-validation? Compare k-fold, stratified, and time series CV.
- What is the ROC curve and AUC? What are their limitations?
- How do you handle class imbalance? Compare different approaches.
- Explain bias-variance tradeoff with a concrete example.