š ML: Classification Metrics ā When to Use What
Confusion matrix:
| Predicted + | Predicted - | |
|---|---|---|
| Actually + | TP | FN |
| Actually - | FP | TN |
Precision = TP/(TP+FP) ā "Of everything I flagged, how many were correct?" ā Use when false positives are costly (spam filter ā don't block real emails)
Recall = TP/(TP+FN) ā "Of everything actually positive, how many did I catch?" ā Use when false negatives are costly (cancer screening ā don't miss cancer)
F1 = 2 Ć (PĆR)/(P+R) ā harmonic mean, balances both.
Accuracy = (TP+TN)/Total ā NEVER use for imbalanced data (predicting majority class always = high accuracy but useless)
ROC-AUC: Good for comparing models. Can be misleadingly optimistic on imbalanced data. PR-AUC: Better than ROC-AUC for imbalanced data ā focuses on the positive class.
Practice Questions
Q: You're building a fraud detection system. What metric do you prioritize and why?