Classifier Evaluation Metrics: Precision, Recall, ROC & F1
Accuracy is the metric that lies to you
Imagine a model that predicts "not fraud" for every single transaction in a dataset where only 0.5% of transactions are fraudulent. That model is 99.5% accurate — and completely useless. It catches zero fraud. This is the single most common mistake in applied machine learning: reporting accuracy on an imbalanced dataset and believing the number means something.
The fix isn't a better model. It's better metrics. Precision, recall, F1, and the ROC curve all exist because accuracy collapses the full behavior of a classifier into one number that hides exactly the failure modes you care about.
The confusion matrix: where every metric comes from
Every classification metric is derived from four counts, organized into a confusion matrix. For a binary classifier predicting a "positive" class (e.g., fraud, disease, churn):
- True Positive (TP) — predicted positive, actually positive
- False Positive (FP) — predicted positive, actually negative (a false alarm)
- True Negative (TN) — predicted negative, actually negative
- False Negative (FN) — predicted negative, actually positive (a miss)
Everything else — precision, recall, F1, accuracy, specificity — is just arithmetic on these four numbers. Once you have the confusion matrix, you can compute any metric you want in seconds.
Precision vs. recall: the fundamental tradeoff
Precision answers: of everything I predicted positive, what fraction was actually positive? High precision means few false alarms.
Recall (also called sensitivity or true positive rate) answers: of everything that was actually positive, what fraction did I catch? High recall means few missed cases.
These two trade off against each other because of the classification threshold. Most classifiers output a probability, and you pick a threshold (commonly 0.5) above which you call it "positive." Lower the threshold and you catch more positives (recall goes up) but you also flag more negatives by mistake (precision goes down). Raise the threshold and the opposite happens. You cannot maximize both simultaneously — the question is always which error costs more in your specific application.
Note
F1 score: a single number when you need one
The F1 score is the harmonic mean of precision and recall: $F1 = 2 \cdot \frac{P \cdot R}{P + R}$. It punishes imbalance between the two — a classifier with 0.9 precision and 0.1 recall gets an F1 of about 0.18, not the misleading 0.5 that a simple average would give. F1 is useful when you need to compare models with one number and don't have a strong reason to weight precision or recall differently.
If one error type matters more than the other, use the F-beta score instead, which lets you weight recall beta times more heavily than precision ($F_2$ favors recall, $F_{0.5}$ favors precision).
The ROC curve and AUC
The ROC curve (Receiver Operating Characteristic) plots the true positive rate (recall) against the false positive rate ($FP / (FP + TN)$) at every possible classification threshold. It visualizes the full tradeoff curve in one picture rather than committing to a single threshold.
The AUC (Area Under the Curve) compresses that curve into one number between 0 and 1. AUC has a clean probabilistic meaning: it's the probability that the model ranks a randomly chosen positive example higher than a randomly chosen negative example. An AUC of 0.5 means the model is no better than random guessing; 1.0 means perfect separation. AUC is threshold-independent, which makes it great for comparing models before you've decided on an operating point.
Note
Which metric to optimize for
| Metric | Best when... | Example use case |
|---|---|---|
| Accuracy | Classes are balanced and errors cost the same | Balanced 50/50 A/B outcome classification |
| Precision | False positives are expensive | Spam filtering, flagging content for manual review |
| Recall | False negatives are expensive | Disease screening, fraud detection |
| F1 score | Need one number balancing precision and recall | Comparing models during experimentation |
| ROC-AUC | Comparing models independent of threshold | Model selection before deployment tuning |
| PR-AUC | Severe class imbalance | Rare-event detection (fraud, defects, anomalies) |
What's next
These metrics are how you judge a classifier after it's trained — but the training process itself, including how a model is fit to minimize error in the first place, is covered in Data Preprocessing & Cleaning for Machine Learning and training-ml. If your classifier is a Naive Bayes model, understanding how its probability estimates are derived connects directly to Bayesian Inference & MAP Estimation.
I build these systems professionally.
Whether it's a RAG pipeline, analytics migration, or AI workflow — let's talk.