ROC & Precision–Recall Explorer
Connect a moving threshold to the confusion matrix, ROC space and the precision–recall curve.
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.
Make a prediction.
Then move a control.
12 positive and 12 negative examples; neither side is perfectly separated.
ROC curve
All negatives are the denominatorRanking summary across thresholds
Precision–recall curve
Predicted positives are the precision denominatorDifferent from trapezoidal PR area
Move the slider, step between score groups, or click either plot to select the nearest operating point.
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.
| Predicted + | Predicted − | |
|---|---|---|
| Actual + | 9TP | 3FN |
| Actual − | 3FP | 9TN |
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.
| Threshold | TP | FP | Recall | FPR | Precision |
|---|
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 versionThe 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 ↗
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.Explain the change.
Test your reasoning.
- Move the threshold and follow the same operating point in both plots.
- Compare performance at low false-positive rate with performance at high recall.
- Inspect tied scores. Why must all cases with the same score change together?