HomeArticlesData Science

Confusion Matrices, ROC Curves and AUC: Reading a Classifier Honestly

TP, FP, TN, FN, the precision-recall trade-off, why AUC is threshold-independent, and when ROC quietly lies to you about a rare positive class.

mysimulator teamUpdated June 2026≈ 8 min read▶ Open the simulation

A threshold turns scores into decisions

Most binary classifiers do not output a hard yes/no — they output a continuous score (a probability, a distance, a logit), and a decision only appears once you pick a threshold: everything above it is called positive, everything below is called negative. Slide that threshold and every downstream metric changes, because you are not changing the model at all — you are changing where you draw the line through the same two overlapping score distributions, one for the true positives and one for the true negatives.

live demo · sliding the threshold across two overlapping score distributions● LIVE

The four outcomes

Every prediction, compared against ground truth, falls into exactly one of four cells:

                  predicted positive     predicted negative
actual positive   True Positive  (TP)    False Negative (FN)
actual negative   False Positive (FP)    True Negative  (TN)

Every classification metric in common use is just some ratio of these four counts. Accuracy = (TP+TN)/total is the most obvious one and the least useful whenever the classes are imbalanced: a model that always predicts "negative" on a dataset that is 99% negative scores 99% accuracy while catching zero positives, which is exactly the failure mode that motivates every other metric below.

Precision, recall, and the trade-off between them

Precision = TP / (TP + FP)     "of everything I called positive, how much really was?"
Recall    = TP / (TP + FN)     "of everything that really was positive, how much did I catch?"
                                (recall is also called sensitivity or true positive rate)

F1 = 2 · Precision · Recall / (Precision + Recall)     harmonic mean of the two

Raising the threshold makes the classifier more conservative: fewer positives are declared, so precision tends to rise (the ones you do call positive are more likely to be right) while recall tends to fall (you miss more real positives by being cautious). Lowering the threshold does the opposite. This is not a bug to be optimised away — it is a real trade-off with no threshold-free solution, and which side of it matters more is a decision about the cost of the two error types, not a property of the model: a cancer screen wants very few missed positives (high recall, tolerating extra false alarms) while a spam filter wants very few real emails misclassified (high precision, tolerating some spam getting through).

The ROC curve and AUC

The receiver operating characteristic (ROC) curve sweeps the threshold through every possible value and plots the true positive rate (recall) against the false positive rate, FPR = FP/(FP+TN), at each one — tracing out the entire trade-off in one picture instead of one number per threshold:

TPR (recall)  = TP / (TP + FN)      y-axis
FPR           = FP / (FP + TN)      x-axis

diagonal TPR = FPR                  a classifier with zero information —
                                     equivalent to guessing at random
curve above the diagonal            genuine discriminative ability
top-left corner (0, 1)              the unreachable ideal: TPR=1, FPR=0

The area under the ROC curve (AUC) condenses the whole curve into one number between 0.5 (no better than random) and 1.0 (perfect separation), and it has a clean probabilistic reading that is worth memorising because it is the reason AUC is threshold-independent: AUC equals the probability that a randomly chosen true positive receives a higher score than a randomly chosen true negative. That is exactly why AUC does not care where you eventually set the threshold — it is measuring how well separated the two score distributions are in the first place, before any threshold decision is made.

When ROC is misleading: the precision-recall curve

ROC's false-positive rate is normalised by the count of true negatives, TN, which is a problem the moment negatives vastly outnumber positives — a huge absolute number of false positives can still be a tiny fraction of an enormous negative class, so FPR barely moves and the ROC curve looks deceptively good even while precision, which is normalised by the (much smaller) number of predicted positives instead, is collapsing. The precision-recall curve plots precision against recall directly and is the standard alternative whenever the positive class is rare — fraud detection, disease screening, rare-event detection — precisely the situations where ROC's optimism is most misleading.

Picking a threshold that isn't 0.5 by default

Nothing makes 0.5 the correct threshold except habit; it is only optimal when false positives and false negatives cost exactly the same and the classes are balanced, which is rarely true in practice. the Youden J statistic, J = TPR − FPR = TPR + TNR − 1, picks the threshold that maximises the vertical distance from the ROC curve to the diagonal — a reasonable default when both error types matter equally — but the honest way to choose a threshold is to attach an explicit cost to a false positive and a false negative and pick whichever threshold minimises the expected total cost, which is exactly what sliding the threshold across the two score distributions in the live demo lets you see happening directly, cell by cell, rather than through a single summary curve.

Frequently asked questions

Why is accuracy a bad metric for imbalanced classes?

Because accuracy weighs every correct prediction equally regardless of class size. On a dataset that is 99% negative, a classifier that always predicts negative scores 99% accuracy while catching zero true positives — a completely useless model by any practical measure. Precision, recall and the precision-recall curve are far more informative in this situation because they are explicitly sensitive to how the rare positive class is being handled.

What does AUC actually mean in plain terms?

AUC is the probability that a classifier gives a randomly chosen true positive example a higher score than a randomly chosen true negative example. An AUC of 0.5 means the model separates the two classes no better than a coin flip; an AUC of 1.0 means every positive scores higher than every negative, so a threshold exists that classifies everything perfectly.

Why does the ROC curve look good even when a model is actually performing poorly on the minority class?

Because the false positive rate on the ROC curve's x-axis is normalised by the total number of true negatives, which can be huge when the positive class is rare — a large absolute number of false positives still ends up as a tiny fraction of that huge negative pool. Precision, by contrast, is normalised by the number of predicted positives, so it exposes the same false positives as a much larger, more honest fraction. This is why the precision-recall curve is preferred whenever the positive class is rare.

Try it live

Everything above runs in your browser — open Confusion Matrix Explorer and change the parameters while it is running. Nothing is installed, nothing is uploaded, the whole model lives in one tab.

▶ Open Confusion Matrix Explorer simulation

What did you find?

Add reproduction steps (optional)