induwara.lk
induwara.lkAI · Machine learning

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.

By Induwara AshinsanaUpdated Jun 10, 2026
ROC curve & AUC calculator

Label is the true class (0 or 1); score is the model's predicted probability or any real-valued output. Separate the two with a space, tab, or comma. Needs at least one positive and one negative row.

Positive class

Which label counts as the positive (event) class.

Score direction

Whether a larger or a smaller score indicates the positive class.

Presets
AUC
0.8056
Area under the ROC curve (0–1)
Gini coefficient
0.6111
2·AUC − 1
Optimal threshold
0.82
max Youden's J = 0.5000
Samples (P / N)
6 / 6
12 total

AUC 0.8056 Excellent discrimination. An AUC of 0.8056 means a randomly chosen positive sample outranks a randomly chosen negative one about 80.56% of the time (ties counted as half).

Decimals

ROC curve

False positive rateTrue positive rate0101
ModelNo-skill (AUC 0.5) Optimal threshold

Formulas

  • TPR = TP / P, FPR = FP / N
  • AUC = Σ (FPRᵢ − FPRᵢ₋₁)·(TPRᵢ + TPRᵢ₋₁)/2
  • AUC = (R⁺ − P(P+1)/2) / (P·N)  (Mann–Whitney)
  • Gini = 2·AUC − 1
  • Youden's J = TPR − FPR

Cross-check. The trapezoidal rule gives AUC = 0.8056; the independent Mann–Whitney rank form (R⁺ = 50 over P = 6, N = 6) gives 0.8056. They reconcile, as they must — the result is verified.

Recommended operating point. Threshold 0.82 maximises Youden's J at 0.5000 — TPR 0.5000, FPR 0.0000 (TP 3, FP 0, TN 6, FN 3).

Threshold table

ThresholdTPFPTNFNTPRFPRYouden's J
0.9510650.16670.00000.1667
0.8820640.33330.00000.3333
0.82optimal30630.50000.00000.5000
0.7831530.50000.16670.3333
0.6541520.66670.16670.5000
0.642420.66670.33330.3333
0.5552410.83330.33330.5000
0.4853310.83330.50000.3333
0.454210.83330.66670.1667
0.3564201.00000.66670.3333
0.2865101.00000.83330.1667
0.2266001.00001.00000.0000

Method: TPR = TP/P, FPR = FP/N swept across every distinct score; AUC = Σ (ΔFPR)(TPR + TPRₚᵣₑᵥ)/2 (trapezoidal, scikit-learn roc_auc_score), cross-checked against the Mann–Whitney rank form (Hanley & McNeil 1982). Sources cited below the calculator. No data leaves this page.

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

  1. 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.
  2. Sweep the threshold through every distinct score. Classify a sample positive when its score meets the threshold, and record the running TPR and FPR — one ROC point per distinct score, with (0,0) prepended and (1,1) appended.
  3. Integrate the area under those points with the trapezoidal rule:

    AUC = Σ (FPRᵢ − FPRᵢ₋₁)·(TPRᵢ + TPRᵢ₋₁)/2

  4. 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

Four samples, no ties — AUC 0.75 (the Textbook preset)

  1. Data (label, score): (1, 0.9) (0, 0.6) (1, 0.4) (0, 0.2). P = 2, N = 2
  2. t = 0.9: TP 1, FP 0 → (FPR 0.0, TPR 0.5)
  3. t = 0.6: TP 1, FP 1 → (0.5, 0.5)
  4. t = 0.4: TP 2, FP 1 → (0.5, 1.0)
  5. t = 0.2: TP 2, FP 2 → (1.0, 1.0)
  6. Trapezoid: 0.25 + 0.50 = 0.75; Gini = 2(0.75) − 1 = 0.5
  7. Mann–Whitney: ranks 0.2→1, 0.4→2, 0.6→3, 0.9→4; R⁺ = 4 + 2 = 6
  8. AUC = (6 − 2·3/2) / (2·2) = 3/4 = 0.75 ✓ (both forms agree)

Tied scores at a threshold — AUC 0.875 (average-rank handling)

  1. Data: (1, 0.8) (1, 0.5) (0, 0.5) (0, 0.2). P = 2, N = 2
  2. t = 0.8: TP 1, FP 0 → (0.0, 0.5)
  3. t = 0.5: a tied 1 and 0 enter together → TP 2, FP 1 → (0.5, 1.0)
  4. t = 0.2: TP 2, FP 2 → (1.0, 1.0)
  5. Trapezoid: 0.375 + 0.50 = 0.875
  6. Mann–Whitney: the two 0.5 share ranks 2 and 3 → average 2.5
  7. R⁺ = 4 (for 0.8) + 2.5 (for the positive 0.5) = 6.5
  8. AUC = (6.5 − 3) / 4 = 0.875 ✓ — ties keep both forms identical

No skill — AUC 0.5 (all scores tied)

  1. Data: (1, 0.5) (0, 0.5) (1, 0.5) (0, 0.5). P = 2, N = 2
  2. One distinct threshold (0.5): every sample is predicted positive
  3. TP 2, FP 2 → the curve runs straight from (0,0) to (1,1)
  4. Trapezoid area of the diagonal = 0.5; Gini = 0
  5. Mann–Whitney: all four ranks average to 2.5; R⁺ = 5
  6. AUC = (5 − 3) / 4 = 0.5 ✓ — exactly the random-guess baseline

Frequently asked questions

Sources & references

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

Rate this tool
Be the first to rate

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.