Scores, curves & thresholds

ROC & Precision–Recall Explorer

Connect a moving threshold to the confusion matrix, ROC space and the precision–recall curve.

10 min to exploreMachine Learning
01 / UNDERSTAND

Where does one threshold sit on the curves, and which curve answers your question?

ROC compares true-positive and false-positive rates. Precision–recall highlights the quality and coverage of positive predictions. Average precision and ROC AUC summarize different relationships.

02 / EXPLORE

Make a prediction.
Then move a control.

02 / One ranking, two views
0.50
Positive means score ≥ threshold.
Walk through the ranking

12 positive and 12 negative examples; neither side is perfectly separated.

ROC curve

All negatives are the denominator
0.792ROC AUC · trapezoidal area
Ranking summary across thresholds

Precision–recall curve

Predicted positives are the precision denominator
0.792Average precision · recall-weighted steps
Different from trapezoidal PR area
Score rankingCurrent thresholdReference line

Move the slider, step between score groups, or click either plot to select the nearest operating point.

Current operating point12 of 24 predicted positive
25.0%False-positive rate
75.0%Recall / true-positive rate
75.0%Precision

TP 9 · FP 3 · FN 3 · TN 9

Connect the point to the decisions

Recall uses the actual positive row. Precision uses the predicted positive column. The ROC x-axis uses the actual negative row.

Confusion matrix · current threshold
Predicted +Predicted −
Actual +9TP3FN
Actual −3FP9TN

One threshold moves a point

The full curves depend on scores and true labels. Moving the threshold changes the highlighted decisions; it does not change ROC AUC or average precision.

Rare positives change the picture

The ROC diagonal is a random-ranking reference. The dashed PR line marks the positive share of this dataset: 50.0%. Try “Rare positives” and inspect how many alerts are correct.

Inspect the threshold groups and calculation

Equal scores move together. The sweep starts above the largest score and ends below the smallest. Average precision adds precision × increase in recall; ROC AUC uses trapezoids. At no positive predictions, precision is undefined; the PR drawing uses (recall 0, precision 1) as a display convention.

ThresholdTPFPRecallFPRPrecision
Discuss

Would a high ROC AUC alone tell you how many of your positive alerts are correct? What extra information does the PR view reveal?

Synthetic datasets only. These are binary, unweighted curves. AUC and average precision summarize rankings; neither selects the right threshold or estimates deployment costs.

An educational experiment with illustrative data. The controls run locally in your browser.

Download the offline classroom version
03 / SEE THE CODE

The idea,
in Python.

A compact implementation of the core concept. Open the code when you are ready to connect the visual to the algorithm.

Open the core implementation Python ↗
Standalone example · illustrative valuesDownload .py
import numpy as np
from sklearn.metrics import (
    roc_curve, precision_recall_curve,
    roc_auc_score, average_precision_score
)

y = np.array([1, 0, 1, 0, 1, 0])
scores = np.array([0.90, 0.80, 0.65, 0.45, 0.30, 0.10])
fpr, tpr, roc_thresholds = roc_curve(y, scores)
precision, recall, pr_thresholds = precision_recall_curve(y, scores)

print("ROC AUC:", roc_auc_score(y, scores))
# Average precision is not trapezoidal PR area.
print("Average precision:", average_precision_score(y, scores))
# PR has one more point than its thresholds array.
04 / TRY IT

Explain the change.
Test your reasoning.

  1. Move the threshold and follow the same operating point in both plots.
  2. Compare performance at low false-positive rate with performance at high recall.
  3. Inspect tied scores. Why must all cases with the same score change together?
← All visual labsNext: Build a Decision Tree

Find your next idea.

Search across courses, research, projects, and resources.

Ideas, connected.esc to close