Semester 1 · Week 12
Model evaluation
- Ch 16 Model Evaluation
+ Research challenge talks
Chapter 16: Model evaluation
Every metric is a choice about what to care about.
Notes · slide 2
Time: 50 minutes. About 30 on the chapter, 10 on the worked example, and 10 to frame the research challenge talks. The talks take the lab slot after the break. Learners do the lab in their own time.
Say: A model is trained. Is it good? "Measure accuracy" is almost the wrong answer. Pick the wrong metric and you optimise the wrong thing, then ship a model that fails in ways that surprise whoever picked it.
Key line: every metric is a choice about what to care about. Ask "good for what?" first.
Next: a metric answering the wrong question.
The metric that answered the wrong question
- Fraud is 0.1% of transactions.
- A model that says "not fraud" every time scores 99.9% accuracy.
- It catches zero fraud.
The metric didn't lie. It answered a question nobody asked.
Notes · slide 3
Say: Fraud is 0.1% of transactions. A model that always says "not fraud" scores 99.9% accuracy. It catches nothing.
Key line: the metric didn't lie. It answered a question nobody asked.
Ask: "Which metric would show this model is useless?" Listen for: recall, which is zero.
Next: where every metric comes from.
The confusion matrix
| Predicted positive | Predicted negative | |
|---|---|---|
| Actually positive | TP | FN: missed it |
| Actually negative | FP: false alarm | TN |
- False positive: Type I error. False negative: Type II.
- Which costs more depends on the domain. In cancer screening, a miss is catastrophic.
Every metric is a formula on this table.
Notes · slide 4
Say: Four counts. Caught it, missed it, false alarm, correctly left alone. A false positive is a Type I error. A false negative is Type II.
Say: Which costs more depends on the domain. In cancer screening a miss is catastrophic. In spam filtering, a false alarm loses someone's real email.
Key line: write down what each error costs before you pick a metric.
Next: the metrics built on it.
Classification metrics
| Metric | Formula | Use when |
|---|---|---|
| Accuracy | allTP+TN | Balanced classes, equal error costs |
| Precision | TP+FPTP | False positives are costly |
| Recall | TP+FNTP | False negatives are costly |
| F1 | P+R2PR | Both matter, classes imbalanced |
Notes · slide 5
Say: Accuracy only works with balanced classes and equal error costs. Rare in practice. Precision: of everything flagged, how much was real? Recall: of everything real, how much did we catch? F1 combines them.
Say: F1 is a harmonic mean, which sits near the smaller number. Precision 1.0 and recall 0.01 average to 0.505, but F1 is 0.0198. A model has to do well on both.
Ask: "A cancer screen. Which matters more?" Listen for: recall.
Next: metrics that don't need a threshold.
Ranking metrics and log loss
- ROC-AUC: how well the model ranks positives above negatives, across all thresholds. 0.5 is random.
- PR-AUC: the same idea for precision and recall. Better for rare events, where ROC-AUC looks flattering.
- Log loss: scores the probabilities themselves. Lower is better.
Notes · slide 6
Say: ROC-AUC measures how well the model ranks positives above negatives, over every threshold. 0.5 is random, 1.0 perfect. Useful for comparing models before you pick a threshold. PR-AUC does the same for precision and recall. It's more honest on rare events. Log loss scores the probabilities themselves, and punishes confident mistakes, as in week 4.
Say: On rare events, true negatives dominate, so the false positive rate stays low and ROC looks flattering. PR doesn't count true negatives.
Next: the curves.
ROC and precision-recall curves

The same model, two views. The PR curve shows the cost of finding the last positives.
Notes · slide 7
Say: Same model, two views. The ROC curve hugs the top-left corner. The PR curve stays near precision 1.0, then drops at the very end. That drop is the model's two mistakes.
Key line: the PR curve shows what it takes to find the last few positives. On rare events, look at it first.
Next: turning a probability into a decision.
The threshold, again
- A classifier outputs a probability. A threshold turns it into a decision.
- Lower it: more recall, less precision.
- Raise it: the reverse.
- 0.5 is a default, not an answer. Choose it from the costs (Chapter 2).
Notes · slide 8
Say: Back to week 1. A probability isn't a decision. The threshold makes it one. Lower it for more recall and less precision. Raise it for the reverse.
Key line: 0.5 is a default, not an answer. The threshold comes from money, not from a metric.
Lab: learners default to F1. Have them say the profit number out loud.
Next: regression metrics.
Regression metrics
| Metric | Sensitive to outliers? |
|---|---|
| MSE | Yes. Used in training: smooth and differentiable |
| RMSE | Yes. Same units as the target |
| MAE | Less |
| MAPE | Less. Breaks near zero |
| R2 | Moderately |
RMSE more than about twice MAE? Outliers are driving it.
Notes · slide 9
Say: MSE squares errors. It's smooth, so it's used in training. RMSE is the same in the target's units. MAE is less swayed by outliers. MAPE gives percentages but breaks when the target can be zero. R² compares against predicting the mean. Below zero means worse than that.
Key line: if RMSE is more than about twice MAE, a few large errors are driving it.
Ask: "Forecasting daily returns, some days zero. MAPE?" Listen for: no. It divides by zero.
Next: are the probabilities honest?
Calibration
- When the model says 70%, is it right 70% of the time?
- High ROC-AUC doesn't mean good calibration.
- It matters when the probability itself drives a decision: pricing, risk, triage.
| Curve shape | Fix |
|---|---|
| S-curve (common in random forests) | Isotonic or Platt scaling |
| Off the diagonal | Isotonic or Platt scaling |
Notes · slide 10
Say: When the model says 70%, is it right 70% of the time? A model can rank well, with high ROC-AUC, and still be over- or under-confident.
Say: It matters when the probability itself drives a decision: insurance pricing, medical risk, triage. Random forests often give an S-shaped curve, under-confident at the extremes. Fix it with isotonic regression or Platt scaling on held-out data.
Ask: "A triage model says 80%, but it's right half the time. What do you do?" Listen for: calibrate it on held-out data.
Next: the gap to the business.
The business metric gap
- An ML metric isn't a business metric.
- Lower RMSE on a demand forecast doesn't maximise profit. Over-stocking and under-stocking cost different amounts.
- Ask: what does one unit of improvement in this metric get the business?
Notes · slide 11
Say: An ML metric isn't a business metric. Lower RMSE on a demand forecast doesn't maximise profit, because over-stocking and running out cost different amounts.
Key line: ask what one unit of improvement in the metric gets the business, not just whether the metric improved.
Say: This is the stock-out exercise from week 1 coming back.
Next: choosing a metric.
Choosing a metric
| Context | Metric |
|---|---|
| Balanced, symmetric errors | Accuracy or F1 |
| Imbalanced classes | F1, PR-AUC |
| False positives expensive (spam) | Precision |
| False negatives expensive (cancer, fraud) | Recall |
| Probabilities drive decisions | Log loss + calibration |
| Rare events | PR-AUC |
Notes · slide 12
Say: Read it as a lookup from the situation. Balanced and symmetric: accuracy or F1. Imbalanced: F1 or PR-AUC. False alarms expensive: precision. Misses expensive: recall. Probabilities drive the decision: log loss and a calibration check. Rare events: PR-AUC.
Ask: "Your capstone. Which row are you in?" Take two or three answers.
Next: the worked example.
Worked example: breast cancer
Logistic regression, 114 test tumours.
- TN 41, FP 1, FN 1, TP 71.
- Accuracy 0.983, precision 0.986, recall 0.986, F1 0.986.
- ROC-AUC 0.995, PR-AUC 0.997, log loss 0.078.
Classes are only mildly imbalanced (37/63), so accuracy and F1 agree. That's when accuracy is acceptable.
Notes · slide 13
Say: Logistic regression, 114 test tumours. One false positive, one false negative. Accuracy 0.983, F1 0.986, ROC-AUC 0.995.
Say: Classes are 37/63, only mildly imbalanced, and both errors are rare. So accuracy and F1 tell the same story.
Key line: that's when accuracy is acceptable. On the 0.1% fraud data, the same metric would mislead.
Next: moving the threshold.
Worked example: moving the threshold
- Sweep thresholds to maximise F1.
- Best threshold: 0.366, not 0.5.
- F1 rises from 0.9861 to 0.9931.
Even on easy data, the default isn't automatically optimal.
Notes · slide 14
Say: Sweep the threshold to maximise F1. The best is 0.366, not 0.5. F1 rises from 0.9861 to 0.9931.
Key line: even on easy data, the default threshold isn't automatically best.
Say: Maximising F1 still treats the two errors as equal. With real costs, a missed malignancy would pull the threshold lower still.
Next: questions this chapter can't answer.
Beyond the book: other questions, other metrics
| Question | Metrics |
|---|---|
| Has the data drifted? | PSI, KL, Jensen-Shannon, Wasserstein |
| How good is a language model? | Perplexity |
| What breaks when we swap models? | Flip rate, negative flip rate |
| Better than accuracy and F1? | MCC, Cohen's kappa, calibration error |
| Rankings and intervals? | NDCG, pinball loss, coverage |
| Is it fair across groups? | Demographic parity, equalised odds |
Notes · slide 15
Say: Chapter 16 grades one classifier against known labels. Stakeholders ask other questions. Has the data drifted? How good is a language model? What breaks when we swap models? Is it fair across groups?
Say: Each row is a question precision and recall can't answer. Perplexity is the exponential of cross-entropy from week 4. The fairness gaps are this chapter's rates, computed per group.
Next: the talks.
Research challenge talks
- Five minutes per pair. Three or four slides.
- What the metric is for, the demo, the failure case.
- End with when to use it instead of a Chapter 16 metric.
Listen for one thing: when would your capstone need this metric?
Notes · slide 16
Say: Five minutes per pair, three or four slides: what the metric is for, the demo, the failure case, and when to use it instead of a Chapter 16 metric.
Do: keep time strictly. A visible timer helps. After each talk, ask the class: "When would you use this instead of F1 or ROC-AUC?"
Do: mark each pair done or not yet against the checklist on the challenge page.
Next: this week's mental model.
Mental model
The confusion matrix is the ground truth. Every metric is a question asked of it.
Before choosing a metric, write down what a false positive and a false negative cost. The right metric usually becomes obvious.
Notes · slide 17
Say: The confusion matrix is the ground truth. Every metric is a question asked of it.
Key line: write down what a false positive and a false negative cost. The right metric usually becomes obvious.
Next: check yourself.
Check yourself
- A spam filter's users hate losing real email. Precision or recall?
- Why can ROC-AUC flatter a model on rare events?
- A model has ROC-AUC 0.95 but its 80% predictions come true 50% of the time. What's wrong, and how do you fix it?
- RMSE is 40, MAE is 12. What does that suggest?
Notes · slide 18
Do: pairs, three minutes, then take answers, before the break and the talks.
Answers: 1. Precision: a false positive loses real email. 2. True negatives dominate the false positive rate, so the curve stays high. 3. Poor calibration. Apply isotonic or Platt scaling on held-out data. 4. A few large errors: outliers.
This week
- Read Chapter 16: Model Evaluation.
- Take the Chapter 16 quiz.
- Run the notebooks: Chapter 16 (opens in a new tab).
- Optional: the further reading for week 12.
Slide 1 of 19: Model evaluation
Keys: → or Space next · ← back · Home/End · F full screen · N notes. Swipe on touch screens. "Save as PDF" opens the print dialog with one slide per page: choose "Save as PDF" as the printer. "Print handout" adds the speaker notes, in black on white.