Cheat sheets
Classification metrics
Confusion matrix, precision, recall, F1, ROC and PR curves, calibration, and how to pick a threshold.
| Predicted positive | Predicted negative | |
|---|---|---|
| Actually positive | TP | FN |
| Actually negative | FP | TN |
| Metric | Formula | Question it answers |
|---|---|---|
| Accuracy | How often is the model right? (misleading when classes are imbalanced) | |
| Precision | Of the alarms, how many were real? | |
| Recall (sensitivity, TPR) | Of the real positives, how many did we catch? | |
| Specificity (TNR) | Of the negatives, how many did we leave alone? | |
| FPR | How often do negatives raise alarms? | |
| F1 | Balance of precision and recall (harmonic mean) | |
| ROC AUC | area under TPR vs FPR | Probability a random positive outranks a random negative |
| PR AUC (average precision) | area under precision vs recall | Ranking quality for rare positives |
| Log loss | Quality of the probabilities themselves | |
| Brier score | Calibration plus sharpness |
Choosing a threshold: minimize on validation data. Lower thresholds raise recall and false positives.
When precision matters more: automated actions, spam filtering, scarce reviewer time. When recall matters more: screening, fraud with human review, safety detection.
Calibration: among predictions near 0.3, about 30% should be positive. Check a reliability diagram; recalibrate with Platt scaling or isotonic regression.
Watch outNever report accuracy alone on imbalanced data, and never tune the threshold on the test set.
Lessons: Classification metrics and thresholds · Logistic regression · Lab: threshold