2.6.9 · D3Model Evaluation & Selection

Worked examples — ROC curve and AUC

4,052 words18 min readBack to topic

This page is the "worked examples" companion to the ROC & AUC topic note. The parent note showed you what a ROC curve and AUC are. Here we throw every kind of situation at them — perfect models, useless models, backwards models, ties, tiny datasets, hugely imbalanced datasets, and an exam-style trap — and grind each one through to a number you can verify.

Before we start, a couple of reminders in plain words so no symbol sneaks in undefined:


The scenario matrix

Every ROC/AUC problem you will ever meet falls into one of these cells. The examples below are each tagged with the cell(s) they cover.

Cell Case class What makes it special Example
C1 Perfect separation Every positive scores above every negative Ex 1
C2 Worse-than-random AUC ; scores are backwards Ex 2
C3 Above-diagonal staircase Alternating labels, signal still present Ex 3
C4 Tied scores Two examples share a score → the 0.5 rule Ex 4
C5 Degenerate: one class empty or → rate undefined Ex 5
C6 Both methods agree Trapezoid area = Mann–Whitney pair count Ex 6
C7 Severe imbalance ROC-AUC looks great but false alarms flood you Ex 7
C8 Real-world / cost twist Pick a threshold under a cost rule Ex 8
C9 Exam trap High accuracy, useless AUC Ex 9

Two tools reappear, so let me name them once, plainly:


Example 1 — Perfect separation (Cell C1)


Example 2 — Worse than random (Cell C2)


Example 3 — Above-diagonal staircase (Cell C3)


Example 4 — Tied scores, the 0.5 rule (Cell C4)


Example 5 — Degenerate: one class is empty (Cell C5)


Example 6 — Both methods must agree (Cell C6)


Example 7 — Severe imbalance (Cell C7)


Example 8 — Real-world cost twist (Cell C8)


Example 9 — Exam trap: high accuracy, useless AUC (Cell C9)


Recall Quick self-test

Perfect ranking gives AUC = ? ::: 1.0 Backwards ranking gives AUC = ? ::: 0.0 (flip predictions to get 1.0) A positive tied with a negative contributes how much to the pairing sum? ::: 0.5 Why is AUC undefined when ? ::: FPR divides by , and the pairing formula divides by . On 95%-healthy data, an "always healthy" model has accuracy ≈ ? and AUC = ? ::: accuracy 0.95, AUC 0.5 When ROC-AUC looks perfect on imbalanced data, which metric reveals the false-alarm flood? ::: Precision (PR-AUC)