In classification, Accuracy (the percentage of total correct predictions) is often dangerously misleading. For example, in fraud detection where only 0.1% of transactions are fraudulent, a trivial model that blindly predicts "Legitimate" for every transaction achieves 99.9% accuracy — yet is completely useless because it fails to catch a single criminal fraud event!
Figure 20.1: The Confusion Matrix Grid and Derived Evaluation Metrics (Precision, Recall, F1, and ROC-AUC).
| Actual Class | Predicted Positive (1) | Predicted Negative (0) |
|---|---|---|
| Actual Positive (1) | True Positive (TP): Correctly flagged as positive. | False Negative (FN): Missed event (Type II Error). |
| Actual Negative (0) | False Positive (FP): False alarm (Type I Error). | True Negative (TN): Correctly identified as negative. |
Precision: Out of all samples predicted as positive, how many were actually positive? Precision = TP / (TP + FP). Crucial when False Positives are costly (e.g., spam filter moving important emails to junk).
Recall (Sensitivity): Out of all truly positive samples, how many did the model find? Recall = TP / (TP + FN). Crucial when False Negatives are catastrophic (e.g., cancer diagnosis or airport weapons screening).
F1-Score: The harmonic mean balancing precision and recall: F1 = 2 · (Precision · Recall) / (Precision + Recall).
The ROC Curve plots True Positive Rate (Recall) against False Positive Rate (FPR = FP / (FP + TN)) across every possible classification threshold from 0.0 to 1.0. The AUC (Area Under the Curve) summarizes performance into a single scalar:
Broaden your foundational and advanced Machine Learning knowledge across our curriculum:
Calibrate decision thresholds from 0.5 to custom operating points.
Track accuracy, precision, and concept drift over time.
Why PR-AUC is preferred over ROC-AUC on imbalanced datasets.
Calculate sensitivity, specificity, and F1-score by hand.