Concept · Chapter 3: Machine Learning
Evaluation Metrics for Classifiers
Accuracy alone can mislead; precision (how many flagged items were right), recall (how many true items were caught) and the confusion matrix show what kind of mistakes a classifier makes.
The problem
On imbalanced problems — fraud, disease, spam — a model that predicts 'no' for everything can score high accuracy while being useless.
The solution
Count the four outcomes (true/false positives/negatives) and summarize them with the metric that matches the cost of each mistake; sweep the decision threshold to see the full trade-off (ROC curve, AUC).
The consequence
Choosing the metric is choosing what the model is for — and a reported number is only meaningful alongside the base rate and the threshold.
You should understand first
- The Turing Test
- Symbolic AI
- Logic and Rules
- Expert Systems
- Knowledge Representation
- The Knowledge-Acquisition Bottleneck
- From Rules to Learning
- Supervised, Unsupervised and Self-Supervised Learning
- Vectors
- Features, Labels and Tasks
- Loss Functions
- Derivatives and Gradients
- Gradient Descent
- Linear Regression
- Probability and Distributions
- Entropy
- Softmax
- Cross-Entropy Loss
- Logistic Regression
- Evaluation Metrics for Classifiers
The four outcomes
| actually positive | actually negative | |
|---|---|---|
| predicted positive | true positive (TP) | false positive (FP) |
| predicted negative | false negative (FN) | true negative (TN) |
Try it
Try it · toy model
Precision, Recall and the Threshold
A fraud detector on imbalanced data: move the threshold and watch precision, recall, the confusion matrix and the ROC curve respond.
Notice two things. With only 10% fraud, "never flag anything" scores 90% accuracy — a weak model can score lower than doing nothing. And moving the threshold never improves precision and recall together; you choose where on the trade-off to sit, based on what a missed fraud costs versus a false alarm. This is the same base-rate logic as Bayes' theorem.
ROC and AUC
The ROC curve plots recall (true-positive rate) against false-positive rate for every threshold at once; the area under it (AUC) is threshold-free: 0.5 is guessing, 1.0 is perfect separation. On heavily imbalanced problems, precision–recall curves are often more informative, because ROC can look good while precision is poor.
What to remember
- Confusion matrix: TP, FP, FN, TN.
- Precision = TP / (TP + FP): of what I flagged, how much was right?
- Recall = TP / (TP + FN): of what was really there, how much did I catch?
- Raising the threshold usually raises precision and lowers recall.
- Always compare against the trivial baseline (e.g. 'always predict the majority class').
Watch
StatQuest with Josh Starmer
ROC and AUC, Clearly Explained!
How to evaluate a classifier across every possible threshold.