Gradient LabStart the lesson

Lessons › Chapter 4: Classification

ROC curves and AUC

The model gives each email a spam score from 0 to 1. Coral balls are real spam, teal are normal. The yellow wall is the cutoff: everything to its right gets flagged as spam.

Watch it move. This lesson is interactive on Gradient Lab: every step is an animated scene you can replay.

Start the interactive lesson

Step by step

Story

Choosing the cutoff

Before picking a cutoff for fraud alerts, Maya wants to know how good the scores are overall.

Concept

Every cutoff is a different filter

The model gives each email a spam score from 0 to 1. Coral balls are real spam, teal are normal. The yellow wall is the cutoff: everything to its right gets flagged as spam.

Build

Slide the cutoff

Lower the cutoff to 0.3 and every spam email is caught, but more normal emails get flagged too. Each position of the wall gives a different catch rate and false-alarm rate.

Key idea

Plot every cutoff: the ROC curve

Slide the cutoff from strict to loose and plot each result: false-alarm rate along the floor, catch rate as height. That staircase is the ROC curve. The dashed diagonal is what pure guessing would give.

Build

Area under the curve

Fill in the space under the curve. The bigger the area, the better the model is at ranking spam above normal email, whatever cutoff you pick. Here the AUC is 0.88.

Insight

Compare two models

A weaker model hugs the diagonal more closely and gets a smaller area. AUC lets you compare models with one number, before choosing any cutoff. 1.0 is perfect, and 0.5 is coin-flipping.

Real life

In real life: card fraud alerts

Card companies score every purchase for fraud risk in a split second. Where they put the cutoff decides how many honest cards get frozen versus how much fraud slips through. AUC tells them how good the scores are before they pick.

Quick check: A model has an AUC of 0.5. What does that tell you?

An AUC of 0.5 matches the random-guessing diagonal: the model can’t tell the classes apart.

Pseudocode

scores = model's spam score for each email (0 to 1)

for cutoff from 1.0 down to 0.0:
    catch_rate  = share of real spam scored above cutoff
    alarm_rate  = share of normal email scored above cutoff
    plot point (alarm_rate, catch_rate)

AUC = area under that curve
# 1.0 = perfect,  0.5 = no better than a coin flip

Key terms

roc curve
A curve showing catches versus false alarms for every possible cutoff.
auc
Area under the ROC curve. 1.0 is perfect, 0.5 is coin-flipping.

Build it: A screening classifier that doesn’t miss cases (35 min, runs in your browser)

See the project