ROC and AUC
Context: FIT2086_MOC · the metric that scores a classifier at every threshold at once, instead of freezing it at · one layer above the single confusion matrix of Classification Evaluation (Confusion Matrix and Metrics) · applied to the probabilities produced by Logistic Regression · the ranking counterpart to the calibration measure Logarithmic Loss
Quick Revision
- 🎯 Objective: sweep the detection threshold from to ➔ trace as a ROC curve ➔ the area under it is the AUC, a threshold-free score.
- 📦 Core Components: small ➔ high sensitivity, more false positives | large ➔ high specificity, more false negatives | perfect · random · perfectly wrong.
- ⚡ Key Constraint: AUC scores only the ranking of the predicted probabilities — a model can rank perfectly () while every probability it reports is badly calibrated.
📝 How It Works
1. The Detection Threshold
- Definition ➔ choose and set whenever , otherwise .
- The default is a choice ➔ classifying by “whichever class is more likely” is exactly ⟹ the argmax rule is one point on a whole family of rules.
- Each is a different classifier ➔ it produces its own confusion matrix, and therefore its own and .
2. The Sensitivity–Specificity Trade-off
- Small ➔ almost everyone is called positive ➔ sensitivity rises, and the price is more false positives (specificity falls).
- Large ➔ only confident cases are called positive ➔ specificity rises, and the price is more false negatives (sensitivity falls).
- No free lunch ➔ high sensitivity is always bought at the expense of specificity and vice versa ⟹ a single confusion matrix reports one arbitrary point on this trade-off.
- Degenerate ends ➔ gives ; gives — the two corners every ROC curve joins.
3. The ROC Curve
- Construction ➔ vary across , plot sensitivity against specificity ➔ the receiver operating characteristic.
- Equivalent axes ➔ the lecture plots sensitivity against specificity with its axis reversed — the same curve, drawn right-to-left.
- Reading the plot ➔ the ideal classifier hugs the top-left corner (all positives caught with no false alarms); the diagonal is random guessing.
- What it fixes ➔ it removes the analyst’s arbitrary choice of from the comparison of two models.
4. AUC — the Area Under That Curve
- Definition ➔ the area under the ROC curve; bigger area = better classifier.
- Bounds and landmarks ➔ perfect classification is achievable · no better than a random guess · perfect misclassification (the model is right about everything, with the labels flipped).
- Probabilistic interpretation ➔ assuming no tied scores, means that for a randomly drawn true positive and a randomly drawn true negative :
- Plain reading ➔ AUC is the probability that the model scores a randomly chosen positive above a randomly chosen negative ⟹ it is a measure of ranking quality, indifferent to the absolute probability values.
- Hand computation ➔ over all positive–negative pairs, count for each correctly ordered pair, for each tie, otherwise, then divide by the number of pairs.
⚖️ Core Decision Matrix
| Measure | What it scores | Threshold needed? | Blind to |
|---|---|---|---|
| Classification accuracy | labels at one operating point | yes () | the trade-off at every other ; class imbalance |
| Sensitivity / specificity | the two error types separately at one | yes | how the pair moves as changes |
| AUC | the ranking across all | no | calibration — the actual probability values |
| Logarithmic Loss | the probability values themselves | no | nothing about ranking, but heavily punishes confident errors |
When It Flips: AUC is the right comparison when the operating threshold is not yet fixed or the classes are imbalanced. Once the deployment threshold is decided by real error costs, sensitivity and specificity at that are what matter — a higher-AUC model can still be the worse choice at your specific operating point.
📊 Exam Execution Trace & Applied Exercises
Applied Exercise — AUC by hand from a ranked score list
Problem: eight test individuals, sorted by predicted . Compute the AUC for each case.
| Case | values in score order (scores ) |
|---|---|
| 1 | — the fourth score is |
| 2 | — the fourth score is |
Final Extracted Output: Case 1 ; Case 2 . Equivalently, of the positive–negative pairs are correctly ordered, and — one badly ranked negative costs of AUC.
⚠️ Common Mistakes
- 💡 Treating as “useless” ➔ useless is ; an AUC of is a perfectly informative model with its labels inverted, and flipping them gives .
- 💡 Reading AUC as an accuracy ➔ it is a probability about pairs, not about individuals; a model can have and terrible accuracy at if the scores are shifted.
- 💡 Quoting sensitivity without its threshold ➔ sensitivity and specificity are meaningless without the that produced them, because both are functions , .
- 💡 Choosing by default in a costly-error setting ➔ optimises the count of mistakes, not their cost; move toward the error you can afford.
🧠 Active Recall
Why is AUC preferred to classification accuracy when comparing two classifiers?
- Hint: What does accuracy silently fix?
Answer
- Short answer: Accuracy scores one arbitrary operating point (); AUC integrates over every threshold, so it compares the models rather than the analyst’s threshold choice.
- Why: Threshold-free ➔ each yields a different confusion matrix and hence a different accuracy ⟹ a model can win at and lose everywhere else. AUC also survives class imbalance, where a majority-class classifier posts a high accuracy with .
A model has but its predicted probabilities are all between and . What is wrong, and which measure exposes it?
- Hint: Ranking versus values.
Answer
- Short answer: Nothing is wrong with its ranking — it orders every positive above every negative — but its probabilities are badly calibrated, claiming near-certainty for the negatives too. Logarithmic Loss exposes it; AUC cannot.
- Why: AUC is order-invariant ➔ any monotone transformation of the scores leaves the AUC unchanged, so it is blind to the values themselves; log-loss scores on the true class and punishes confident errors heavily.
You lower from to on a cancer screening test. State the direction of both error types and justify the move.
Answer
- Short answer: Sensitivity rises and false negatives fall; specificity falls and false positives rise. For screening this is the right trade — a missed cancer is far costlier than a follow-up test on a healthy patient.
- Why: Threshold monotonicity ➔ lowering moves individuals from to only, so and can only increase and , can only decrease ⟹ , , tracing the ROC curve up and to the right.