ROC Curve & AUC Calculator
Paste your binary labels and predicted scores to get the ROC curve, the AUC, the Gini coefficient, and the Youden-optimal threshold — every value shown with its formula and cross-checked two ways. It matches scikit-learn's roc_auc_score, runs entirely in your browser, and needs no signup.
How it works
The ROC curveplots a classifier's true positive rate against its false positive rate as the decision threshold moves, and the AUCis the single number underneath it. The method here follows scikit-learn's roc_curve / roc_auc_score and the definitions in Fawcett's 2006 ROC primer.
With P positive and N negative samples, each threshold yields a confusion matrix and a point:
TPR = TP / P FPR = FP / N
- Sortthe samples by predicted score, descending. If you pick “lower score = positive”, the scores are negated first so the sweep can always treat a higher value as more positive.
- Sweep the threshold through every distinct score. Classify a sample positive when its score meets the threshold, and record the running
TPRandFPR— one ROC point per distinct score, with(0,0)prepended and(1,1)appended. - Integrate the area under those points with the trapezoidal rule:
AUC = Σ (FPRᵢ − FPRᵢ₋₁)·(TPRᵢ + TPRᵢ₋₁)/2
- Cross-checkwith the Mann–Whitney / Wilcoxon rank form (Hanley & McNeil 1982). Rank every score ascending — averaging ranks for ties — and with
R⁺the sum of the positive ranks:AUC = (R⁺ − P(P+1)/2) / (P·N)
This equals the probability that a random positive outranks a random negative (ties counted as half) and must match the trapezoidal value — the tool asserts the two agree to floating-point precision.
From the AUC the tool reports the Gini coefficient = 2·AUC − 1 and a plain-English discrimination band. For each threshold it also computes Youden's J = TPR − FPR; the threshold with the highest J — the point on the curve furthest from the no-skill diagonal — is flagged as a common operating-point choice. Inputs with only one class are rejected, because the AUC is then undefined.
Worked examples
Frequently asked questions
Sources & references
- scikit-learn — sklearn.metrics.roc_auc_score (reference TPR/FPR sweep and trapezoidal AUC)
- scikit-learn — sklearn.metrics.roc_curve (threshold sweep and ROC points)
- Fawcett, T. (2006) — An introduction to ROC analysis, Pattern Recognition Letters 27(8)
- Hanley & McNeil (1982) — The Meaning and Use of the Area under a ROC Curve, Radiology 143(1)
The formulas on this page were last cross-checked against these sources on 2026-06-10. ROC and AUC are stable mathematical definitions, so this tool needs no rate or schedule updates — only the worked examples are periodically re-reconciled against scikit-learn.
Related tools
Comments & feedback
Spotted a bug or want an improvement? Tell us — our team reviews every comment, and good ideas get built. Comments are public and anonymous.
Found a bug, edge case, or want to suggest an improvement?
Email me at [email protected] — most fixes ship within 24 hours.