Plot ROC / PR curves and pick your best decision threshold

Paste raw model scores and their true 0/1 labels. This tool sweeps every candidate threshold, builds the full confusion matrix at each cut, draws the ROC and precision–recall curves, integrates the area under each, and highlights the operating point that maximizes F1 or Youden’s J. Everything runs locally in your browser — no data leaves the page.

ROC AUC
Avg Precision (PR AUC)
Best threshold
Positives / Negatives

ROC curve

Precision–Recall curve

Confusion matrix at chosen threshold (0.50)

Pred 1 / Pred 0
Actual 1
/
Actual 0
/
MetricValue
Accuracy
Precision
Recall (TPR)
Specificity (1−FPR)
F1 score
Youden’s J

How the threshold sweep works

A binary classifier outputs a continuous score (a probability or logit). To turn scores into decisions you pick a threshold t: predict positive when score ≥ t. Every distinct score in your data is a candidate cut point, so the tool sorts the (score, label) pairs in descending order and walks the list, moving one example at a time from the “predicted negative” side to the “predicted positive” side. This incrementally updates the four confusion-matrix counts — true positives (TP), false positives (FP), false negatives (FN), true negatives (TN) — without recomputing them from scratch, giving an exact O(n log n) sweep.

At each threshold it derives the two ROC axes: the true-positive rate TPR = TP / (TP + FN) and the false-positive rate FPR = FP / (FP + TN). Plotting TPR against FPR traces the ROC curve; a diagonal is random guessing and the top-left corner is perfect separation. The precision–recall curve plots precision = TP / (TP + FP) against recall = TPR, which is far more informative than ROC when positives are rare.

Area under each curve is computed with the trapezoidal rule: for consecutive points the tool adds ½ · (x₂ − x₁) · (y₂ + y₁). The ROC integral yields ROC-AUC (the probability a random positive outranks a random negative), and the PR integral yields average precision. Curves are monotonic in FPR/recall so the areas are stable and threshold-independent.

Threshold selection then scores every candidate cut. Youden’s J = TPR − FPR finds the point furthest above the ROC diagonal — a good default when the classes and error costs are balanced. F1 = 2·precision·recall / (precision + recall) is the harmonic mean, preferred for imbalanced data where you care about the positive class. The green marker on each plot shows the winning operating point, and the confusion matrix plus per-threshold metrics update live as you drag the manual slider — letting you trade recall for precision by eye before committing a threshold to production.

Related Tools