ROC Curves vs Precision-Recall Curves: Choosing the Right Threshold

Why a classifier's raw output is a sliding threshold rather than a fixed decision, and how ROC and precision-recall curves reveal the real tradeoff between catching positives and avoiding false alarms.

▶ Open the simulation

A classifier is a slider, not a switch

Most classification models, from logistic regression to gradient-boosted trees to neural networks, do not output a hard yes-or-no answer. They output a probability, or a probability-like score, between 0 and 1 — a model might say a given email has a 0.83 probability of being spam. To turn that score into an actual decision, you pick a threshold: anything above the threshold gets classified positive, anything below gets classified negative. The default threshold most people reach for automatically is 0.5, but there is nothing mathematically special about 0.5, and changing it changes the model's behaviour dramatically without retraining anything.

Every threshold produces a different confusion matrix — a different count of true positives, false positives, true negatives and false negatives — and therefore a different set of derived metrics. Raise the threshold and the model becomes more cautious about calling something positive, which reduces false positives but increases false negatives (it misses more real positives). Lower the threshold and the reverse happens: more true positives get caught, but at the cost of more false alarms. This tradeoff is unavoidable and is the entire reason ROC and precision-recall curves exist: rather than reporting one number at one arbitrary threshold, they show how performance changes across the whole range of possible thresholds at once.

Building the ROC curve

The Receiver Operating Characteristic (ROC) curve, a name inherited from radar signal detection research in the 1940s, plots the true positive rate against the false positive rate as the decision threshold sweeps from 1 down to 0. The true positive rate, also called recall or sensitivity, is the fraction of actual positives the model successfully catches: TP / (TP + FN). The false positive rate is the fraction of actual negatives the model incorrectly flags as positive: FP / (FP + TN).

At a threshold of 1, the model calls nothing positive, so both rates are 0 and the curve starts at the origin. As the threshold is lowered, more cases get classified positive: true positives accumulate (raising the true positive rate) but so do false positives (raising the false positive rate). At a threshold of 0, everything is classified positive, both rates hit 1, and the curve ends at the top-right corner. A perfect classifier — one whose scores cleanly separate positives from negatives with no overlap — would trace a curve that shoots straight up the left edge to a true positive rate of 1 while the false positive rate is still 0, then straight across; a classifier that is no better than random guessing traces the diagonal line from corner to corner, since raising your true positive rate by chance costs you an equal rise in false positive rate.

The area under this curve, AUC, condenses the whole curve into one number between 0.5 (random) and 1.0 (perfect), and has a clean probabilistic interpretation: it is the probability that the model ranks a randomly chosen true positive example higher than a randomly chosen true negative example. AUC is popular because it is threshold-independent, letting you compare two models' overall ability to separate classes without committing to a specific operating point in advance.

Building the precision-recall curve

The precision-recall curve plots precision against recall as the same threshold sweeps across its range. Recall is identical to the true positive rate used in the ROC curve. Precision, by contrast, is a different quantity entirely: of everything the model called positive, what fraction actually was positive? TP / (TP + FP). Where the ROC curve's false positive rate is measured against the pool of actual negatives, precision is measured against the pool of predicted positives — a subtle but consequential difference.

At a very high threshold, the model only flags the cases it is most confident about, so precision tends to be high (few of its positive calls are wrong) but recall is low (it is missing most of the true positives, since it is being so cautious). Lowering the threshold recovers more true positives, raising recall, but typically at the cost of dragging in more false positives too, which lowers precision. A model that perfectly separates the classes traces a curve that stays at precision 1.0 across the full range of recall; a poor model's curve sags down toward the baseline, which for precision-recall (unlike ROC) is not a fixed diagonal but sits at a height equal to the proportion of positives in the dataset overall.

Why the choice between the two curves matters most with imbalanced data

Both curves are legitimate summaries of a classifier's threshold-by-threshold behaviour, but they respond very differently to class imbalance, which is why the right choice depends heavily on your dataset. Consider a fraud detection problem where only 0.5% of transactions are actually fraudulent, so true negatives (the vast pool of legitimate transactions correctly identified as legitimate) massively outnumber every other category. The false positive rate used in ROC is calculated as FP / (FP + TN); because TN is enormous, even a fairly large absolute number of false positives barely moves the false positive rate, so the ROC curve can look deceptively strong — hugging close to the top-left corner — even for a model that in practice generates so many false alarms that it would be unusable.

Precision does not have this blind spot, because its denominator, TP + FP, never includes the mass of true negatives at all. If a model floods its positive predictions with false alarms, precision drops sharply and visibly, regardless of how enormous the negative class is. This is why the standard advice in model evaluation is to prefer the precision-recall curve, and its own summary statistic (average precision, or PR-AUC), whenever the positive class is rare relative to the negative class — fraud detection, disease screening, rare-event alerting — and to prefer ROC-AUC when classes are roughly balanced or when the cost of false positives and false negatives should be weighed symmetrically against the full population of negatives.

Picking an actual operating threshold

Both curves describe performance across every possible threshold, but a deployed system still has to commit to one specific threshold to make real decisions. That choice should be driven by the relative business cost of the two error types, not by a default like 0.5. In medical screening, a false negative (missing a real case of disease) is typically far more costly than a false positive (an unnecessary follow-up test), which argues for a lower threshold that favours high recall even at some cost to precision. In a spam filter, a false positive (a legitimate email wrongly binned as spam, potentially never seen) can be more damaging to the user than a false negative (one spam email that slips through), arguing for a higher threshold that favours precision.

A practical way to choose is to walk along the ROC or precision-recall curve and identify the point where the tradeoff between the two error types matches your actual costs — sometimes formalised with the F-beta score, a weighted combination of precision and recall where the beta parameter lets you tune how much more the metric should value recall over precision (beta greater than 1) or precision over recall (beta less than 1). Visualizing the confusion matrix update live as a threshold slider moves across the curve, watching true positives, false positives, precision and recall all shift together in real time, makes this tradeoff far easier to reason about than reading the curve as a static image and picking a point by eye.

Frequently Asked Questions

If ROC-AUC and PR-AUC are both single summary numbers, why not just always use ROC-AUC since it seems more standard?

ROC-AUC is standard and useful for balanced classification problems, but it can give an overly optimistic picture of a model's usefulness on imbalanced data, because its false positive rate is diluted by a large pool of true negatives. On a highly imbalanced dataset, two models can have similar, high ROC-AUC scores while one produces far more false alarms in absolute and practical terms than the other; PR-AUC exposes that difference because precision is sensitive to the absolute count of false positives relative to true positives, not relative to the whole negative population.

What does an AUC of exactly 0.5 mean, and can AUC be below 0.5?

An AUC of 0.5 means the model's ranking of positive versus negative examples is no better than random guessing; the ROC curve sits on the diagonal. AUC can technically fall below 0.5, which would mean the model is systematically ranking negatives above positives, worse than random. In practice this almost always signals a bug, such as accidentally inverted labels, rather than a model that has genuinely learned to be anti-predictive, since simply flipping its predictions would immediately push its AUC above 0.5.

Does changing the classification threshold require retraining the model?

No. The threshold is applied after the model has already produced its probability score; changing it from, say, 0.5 to 0.3 is just a different rule for converting that same score into a positive or negative decision. No weights, parameters or training data change. This is exactly why ROC and precision-recall curves can be drawn from a single trained model's output scores by simply recomputing the confusion matrix at many different threshold values.

How do I compute the confusion matrix components (TP, FP, TN, FN) that feed into these curves?

For a given threshold, every example the model scored gets sorted into one of four buckets by comparing its predicted label (positive if score is above the threshold, negative otherwise) against its true label: true positive (predicted positive, actually positive), false positive (predicted positive, actually negative), true negative (predicted negative, actually negative), and false negative (predicted negative, actually positive). Recomputing these four counts at each of many threshold values, and calculating true positive rate, false positive rate, precision and recall from them at each step, is exactly how both curves are traced out point by point.

What did you find?

Add reproduction steps (optional)