Free browser-based ML tool

ROC-AUC & PR Curve Calculator

Plot ROC and Precision-Recall curves from pasted y_true and y_score CSV data in your browser. Tune thresholds, find Youden’s J & best F1, and export code.

Free to useNo upload or sign-inRuns entirely in your browser
Live calculation
Powered by @kanaries/ml

1. Paste binary labels & predicted scores

y_true, y_score (CSV or TSV)
Column 1: binary ground truth (0/1). Column 2: probability or continuous decision score.
y_truey_score
2. Operating decision threshold
Threshold0.500

ROC-AUC, Precision–Recall & threshold metrics

ROC-AUC
0.8500
Avg Precision (PR)
0.8643
F1 @ Threshold
0.8000
Youden’s J
0.6000
Recall (TPR)
0.8000
Precision (PPV)
0.8000
FPR (1 − Spec)
0.2000
Brier Score
0.1586

ROC Curve (AUC = 0.850)

0.000.000.250.250.500.500.750.751.001.00False Positive Rate (FPR)True Positive Rate (TPR)

Precision–Recall (AP = 0.864)

0.000.000.250.250.500.500.750.751.001.00Recall (TPR)Precision
Threshold pointThresholdTP / FP / FN / TNPrecisionRecallF1Youden’s J
Current operating point0.5008 / 2 / 2 / 80.8000.8000.8000.600
Optimal Youden’s J0.4109 / 3 / 1 / 70.7500.9000.8180.600
Optimal F10.4109 / 3 / 1 / 70.7500.9000.8180.600
import { Metrics } from '@kanaries/ml';

const yTrue = [1,1,1,1,0,1,1,0,1,1,0,1,0,0,0,1,0,0,0,0];
const yScores = [0.96,0.91,0.87,0.82,0.78,0.74,0.69,0.63,0.58,0.52,0.47,0.41,0.36,0.31,0.26,0.21,0.17,0.12,0.08,0.04];

const rocAuc = Metrics.rocAucScore(yTrue, yScores, 1);
const roc = Metrics.rocCurve(yTrue, yScores, 1);
const pr = Metrics.precisionRecallCurve(yTrue, yScores, 1);

const threshold = 0.5;
const yPred = yScores.map((s) => (s >= threshold ? 1 : 0));

console.log({
  rocAuc,
  f1: Metrics.f1Score(yPred, yTrue),
  precision: Metrics.precisionScore(yPred, yTrue),
  recall: Metrics.recallScore(yPred, yTrue),
  rocPoints: roc.fpr.length,
  prPoints: pr.recall.length,
});

What is an ROC curve and why does ROC-AUC matter?

Binary classifiers rarely output hard 0/1 decisions natively. Instead, models such as logistic regression, random forests, gradient boosting, and neural networks output continuous probabilities or decision scores. Turning those scores into operational actions requires choosing a decision threshold—for example flagging every transaction above 0.50 as fraud.

Evaluating a model at a single threshold hides how well the underlying ranking behaves across stricter or more permissive cutoffs. The Receiver Operating Characteristic (ROC) curve sweeps the threshold across every distinct score in your dataset and plots the True Positive Rate (Recall / Sensitivity) on the vertical axis against the False Positive Rate (1 − Specificity) on the horizontal axis. The area underneath that curve—ROC-AUC—compresses ranking quality into a single threshold-free number between 0 and 1.

ROC-AUC has a direct probabilistic interpretation: if you pick one true positive observation and one true negative observation at random, ROC-AUC is the probability that your model assigned a higher score to the positive case. A random model traces the diagonal baseline and scores 0.50; a perfect separator hugs the top-left corner and scores 1.00.

ROC curve vs Precision–Recall (PR) curve on imbalanced datasets

While ROC-AUC is scale-invariant and unaffected by class prevalence, that same property can create a blind spot when positives are rare. Suppose only 2% of events are fraudulent. Raising false positives from 20 to 200 barely nudges the False Positive Rate because the denominator contains tens of thousands of true negatives—so the ROC curve still looks near-perfect. Meanwhile, an investigation team reviewing those alerts sees precision plummet from 50% to under 10%.

The Precision–Recall (PR) curve eliminates true negatives from both axes, plotting Precision (positive predictive value) against Recall (true positive rate). Its baseline is not a fixed diagonal at 0.50, but a horizontal line equal to the dataset’s positive class prevalence (shown as the dashed line in the PR chart above). Comparing the Imbalanced Fraud preset against the Well-Separated preset demonstrates this difference immediately: even when ROC-AUC stays high, Average Precision reacts sharply to false positives near the top of the score ranking.

Rule of thumb: report ROC-AUC when both classes matter equally or you want a prevalence-invariant ranking metric; report Average Precision (PR-AUC) alongside operating-point precision and recall whenever positive events are rare and false alarms carry direct review cost.

Choosing the right decision threshold: Youden’s J vs Best F1

Ranking metrics tell you which model orders examples better, but shipping a classifier still requires selecting a concrete cutoff. Dragging the threshold slider in the tool above moves the red operating marker simultaneously along both the ROC and PR curves and updates the exact TP, FP, FN, and TN counts in real time.

Youden’s J statistic (TPR − FPR)

Youden’s J equals Sensitivity + Specificity − 1 and identifies the point on the ROC curve farthest above the random diagonal. It treats a 1% gain in true-positive rate as equally valuable to a 1% reduction in false-positive rate—making it a principled default for balanced diagnostic tests and balanced binary classification problems.

Best F1 threshold

When class imbalance is severe or true negatives are abundant, maximizing Youden’s J can still produce too many false alarms. Jumping to the Best F1 threshold maximizes the harmonic mean of precision and recall instead, focusing strictly on positive-class detection quality. For asymmetric business problems (such as automated payment blocking vs manual review queues), start from Best F1 or Youden’s J and fine-tune until precision or recall meets your operational SLA.

Checking probability calibration with the Brier score

Notice an important subtlety: ROC-AUC and PR curves are purely rank-based. Multiplying every predicted probability by 0.1 leaves ROC-AUC and Average Precision completely unchanged—even though the raw numbers are now wildly miscalibrated. Whenever your pasted scores lie in [0, 1], this calculator also computes the Brier score (mean squared error between predicted probabilities and binary outcomes, where lower is better). If your model achieves strong ROC-AUC yet poor Brier score, apply Platt scaling or isotonic calibration using Calibration.CalibratedClassifierCV.

Common ROC-AUC & Precision–Recall pitfalls in practice

Even experienced machine learning teams misread ranking curves when moving from a notebook to production. Watch out for four frequent failure modes whenever you interpret the plots above:

  • Tuning thresholds on the test set: Selecting the Youden’s J or Best F1 threshold on your final evaluation split leaks information and inflates reported F1. Always choose the operating threshold on a dedicated validation split or out-of-fold cross-validation predictions, then freeze that cutoff before scoring the held-out test set.
  • Tied scores and coarse model outputs: Shallow decision trees, k-NN with small k, and rule-based scorecards often assign identical scores to many rows. On the ROC curve, tied scores create diagonal line segments rather than pure horizontal/vertical steps, because all tied rows cross the decision boundary together. Use continuous probabilistic estimators or ensemble averaging if you need fine-grained threshold control.
  • Comparing PR curves across different datasets: Because the Precision–Recall baseline equals positive prevalence, an Average Precision of 0.45 on a 1% fraud sample represents a massive 45× lift over chance, whereas 0.45 on a 50/50 balanced dataset is worse than random guessing. Never compare AP across datasets with different positive rates without reporting prevalence alongside it.
  • Ignoring high-precision or low-FPR operating regions: Two models can share an identical overall ROC-AUC of 0.88 while behaving very differently in the far-left region (FPR < 2%) where automated fraud blocks or email spam filters actually operate. Always inspect the left tail of the ROC curve and the right tail of the PR curve rather than relying solely on the aggregate area.

JavaScript & Python parity with @kanaries/ml

Every ROC point, AUC area, and Precision–Recall threshold rendered in this calculator runs directly in your browser via Metrics.rocCurve, Metrics.rocAucScore, and Metrics.precisionRecallCurve from @kanaries/ml, with Average Precision verified against sklearn.metrics.average_precision_score. Copy the generated JavaScript or Python tabs to reproduce the exact curves in unit tests, Node.js evaluation scripts, or Jupyter notebooks, or click Share link / Embed in the header bar to share this threshold experiment with your team.

Frequently asked questions

Questions about roc-auc & pr curve calculator

What is ROC-AUC and how should I interpret it?

ROC-AUC (Area Under the Receiver Operating Characteristic curve) measures how well a classifier ranks positive instances above negative instances across every possible decision threshold. A score of 0.5 equals random guessing, 1.0 indicates perfect separation, and an AUC of 0.85 means a randomly chosen positive receives a higher score than a randomly chosen negative 85% of the time.

When should I use a Precision-Recall (PR) curve instead of ROC?

Use a Precision-Recall curve and Average Precision (AP) whenever the positive class is rare—such as fraud detection, churn alerts, or rare medical screening. ROC curves can look optimistically high on imbalanced datasets because a large true-negative count keeps the false-positive rate small even when false alarms overwhelm precision.

How is Average Precision (AP) calculated here?

This calculator computes exact scikit-learn Average Precision: the weighted sum of precisions at each threshold, with the increase in recall from the previous threshold used as the weight. Unlike trapezoidal interpolation on PR curves, step-wise Average Precision avoids optimistic linear interpolation between sparse recall points.

What is Youden’s J statistic for choosing an optimal threshold?

Youden’s J equals Sensitivity + Specificity − 1, or equivalently TPR − FPR. Geometrically, it maximizes the vertical distance between the ROC curve and the random diagonal line. It is a clean default when false positives and false negatives carry comparable weight; for asymmetric business costs, compare it against the Best F1 threshold or set a custom cost cutoff.

Does this calculator accept raw decision scores or only probabilities?

Both work for ROC-AUC, Precision-Recall curves, Youden’s J, and F1 because ranking metrics only depend on score order. When all pasted scores fall in [0, 1], the tool also reports the Brier score to evaluate probability calibration quality.

Is my pasted CSV data uploaded to a server?

No. All curve computation, threshold evaluation, PNG rendering, and CSV exports run locally inside your browser using @kanaries/ml. You can also copy a shareable link or embeddable iframe without sending data to a backend.

Powered by @kanaries/ml — the scikit-learn-style ML library for JavaScriptnpmGitHub