Area Under Curve (AUC)

How the ROC curve is produced

Example (5 items, 3 pos / 2 neg, sorted by score)

item label score
A P 0.9
B P 0.8
C N 0.6
D P 0.4
E N 0.2

Sweep threshold just below each score (denominators: pos=3, neg=2):

below predicted + TP FP TPR FPR
0.9 A 1 0 0.33 0.0
0.8 A,B 2 0 0.67 0.0
0.6 A,B,C 2 1 0.67 0.5
0.4 A,B,C,D 3 1 1.00 0.5
0.2 all 3 2 1.00 1.0

Why area = P(pos ranked above neg)

Pseudocode (the definition is the algorithm)

def auc(scores, labels):
    pos = [s for s, y in zip(scores, labels) if y == 1]
    neg = [s for s, y in zip(scores, labels) if y == 0]
    wins = 0.0
    for p in pos:
        for n in neg:
            if p > n:   wins += 1.0
            elif p == n: wins += 0.5   # tie = half credit
    return wins / (len(pos) * len(neg))

AUC score - area under the curve

More AUC is better