Model Evaluation
Confusion matrices, accuracy, precision, recall, F1 score, ROC curves, and AUC â the toolkit for measuring classifier and regressor performance.
Positive
Negative
Model evaluation measures how well a trained model performs on data it hasn't seen. Choosing the right metrics depends on the task.
For classification:
- Accuracy: fraction of correct predictions =
- Precision: â of predicted positives, how many are right?
- Recall (Sensitivity): â of actual positives, how many did we catch?
- F1 score:
Confusion matrix: shows all four outcomes (TP, TN, FP, FN) for a binary classifier.
- Precision and recall trade off against each other as the decision threshold moves â improving one typically costs the other
- Accuracy alone is uninformative (even misleading) on imbalanced datasets
- F1 score is the harmonic mean of precision and recall, so it's dominated by whichever of the two is smaller
- AUC-ROC is threshold-independent â it summarizes performance across every possible decision threshold at once
- Reporting accuracy alone on an imbalanced dataset: a model that always predicts the majority class can score deceptively high accuracy while being useless
- Choosing a metric after seeing results, to make a model look good: the metric should reflect the real-world cost of false positives vs. false negatives, decided before evaluation
A cancer screening test: 90 patients have cancer (positive), 910 don't (negative). The model predicts 80 TP, 10 FN, 15 FP, 895 TN.
Accuracy = 975/1000 = 97.5%. But recall = 80/90 = 89%. The model misses 10% of cancer cases â arguably unacceptable for a screening tool, even though overall accuracy looks excellent.
A fraud detection model has 99.5% accuracy on a dataset where 0.5% of transactions are fraudulent. Is this impressive? What metric is more appropriate?
Solution
Not impressive at all â a model that always predicts "not fraud" achieves 99.5% accuracy without detecting a single fraudulent transaction!
For imbalanced classes, use precision, recall, F1, or AUC-ROC. With fraud as the positive class:
- Recall matters most (catching fraud cases)
- Precision matters for avoiding false positives (annoying legitimate customers)
- F1 balances these; AUC measures tradeoff across all thresholds
Never use accuracy alone for imbalanced datasets.
Related concepts
Needs first