Module 10 · Evaluation: does the model work, for whom, and how sure are we?
Time: about 7 hours with readings · Lab: python course/labs/lab10_evaluation.py
You need: Module 1 (training, validation and test data; what a score is) and Module 2 Part B: conditional probability (§6), mean and standard deviation (§9), the standard error (§11) and the 95% interval (§12).
By the end you can:
- decide before testing what will be measured, against what ground truth, and what result counts as success;
- read a confusion matrix and compute precision, recall and F1 by hand, and say which matters for which decision;
- explain why accuracy can mislead, and what macro and weighted averages do;
- explain thresholds as a trade-off (precision vs recall, review work vs errors), including ROC and selective classification;
- check whether a model's scores can be trusted as probabilities (calibration);
- put an honest uncertainty range on any accuracy figure, and work out how many examples a test needs;
- evaluate amounts (portion or waste estimates) against weighed values: bias, MAE and limits of agreement;
- turn every metric into a sentence a kitchen manager can act on.
Why this matters for the internship
This is the module closest to the job. The position description asks you to "support evaluation of food and portion identification accuracy", "assist with testing AI and machine learning outputs against actual operational outcomes", "support comparison of PoC results against agreed performance measures" and "translate technical outputs into meaningful operational insights". Each section below is one of those tasks, worked through on TrayCheck's real numbers.
TrayCheck's dashboard Model performance tab shows the same things: the confusion matrix, per-dish precision and recall, the threshold trade-off and the confident mistakes.
1. Start with the decision, not the metric
A metric is only useful if it answers a question someone will act on. Before testing anything, write down four things. This is what "agreed performance measures" means in practice.
| Decide | Question to answer | TrayCheck example |
|---|---|---|
| The decision | What will people do differently depending on the result? | Trust the dish labels in waste-per-dish reports, or not |
| The ground truth (reference standard) | What do we compare the model's output with, and how good is that reference? | The dish label checked by a person; for amounts, the plate weighed on a scale |
| The metric and the target | Which number, and what value counts as good enough? | At most 5% wrong labels among trays nobody reviews |
| The test set | Which examples, how many, from where and when? | 160 photos never used in training or tuning (Module 9) |
Two more things belong on the list:
- A baseline. Compare against what happens today, not only against guessing. If staff currently estimate plate waste by eye, the question is whether the AI is better than staff estimates, not whether it is perfect.
- The cost of each kind of error. A wrong dish label silently moves waste from one dish to another in the reports. A flagged photo costs a person a few seconds. Because those costs differ, TrayCheck sends borderline cases to review instead of auto-accepting them.
Writing these down before seeing results stops the evaluation from drifting toward whichever number looks best afterwards.
2. The confusion matrix and per-class metrics
A confusion matrix counts every combination of real answer (row) and predicted answer (column). Correct predictions sit on the diagonal. TrayCheck's 160 test photos:
predicted as
real dish ribs beet salad bibimbap bread pudding row total
ribs 36 0 1 3 40
beet salad 1 36 2 1 40
bibimbap 0 1 37 2 40
bread pudding 3 1 3 33 40
column total 40 38 43 39 160
Read one row: of 40 real bread puddings, 33 were named correctly, 3 were called ribs, 1 beet salad and 3 bibimbap. Read one column: of 43 photos the model called bibimbap, 37 really were.
To get metrics for one dish, treat the problem as "this dish versus everything else":
- True positive (TP): really this dish, predicted this dish (the diagonal cell).
- False positive (FP): predicted this dish, but it was another (the rest of its column).
- False negative (FN): really this dish, predicted as another (the rest of its row).
| Dish | TP | FP | FN | Precision | Recall | F1 |
|---|---|---|---|---|---|---|
| Ribs | 36 | 4 | 4 | 0.900 | 0.900 | 0.900 |
| Beet salad | 36 | 2 | 4 | 0.947 | 0.900 | 0.923 |
| Bibimbap | 37 | 6 | 3 | 0.860 | 0.925 | 0.892 |
| Bread pudding | 33 | 6 | 7 | 0.846 | 0.825 | 0.835 |
These match scikit-learn's classification_report exactly.
Written as conditional probabilities (Module 2 §6): precision = P(really this dish | predicted this dish) and recall = P(predicted this dish | really this dish). Same correct photos on top, different "given" underneath.
What each one answers:
- Precision: "When the model says bibimbap, how often is it bibimbap?" Bibimbap has the lowest precision, 0.86: about 1 in 7 trays recorded as bibimbap is something else. The model over-uses that label, which also shows up in its confident mistakes.
- Recall (also called sensitivity): "Of the real bread puddings, what share did the model find?" 0.825: about 1 in 6 bread puddings is recorded as another dish.
- F1: a single number that is high only if both precision and recall are high. An ordinary average would let one excellent number hide a terrible one: precision 1.0 with recall 0.1 averages to 0.55, which sounds respectable for a model that misses 9 cases in 10. F1 uses the harmonic mean instead, 2 × P × R / (P + R), which is pulled toward the smaller of the two: 2 × 1.0 × 0.1 / 1.1 = 0.18.
Which matters depends on the decision. If the PoC is used to find every tray containing an allergen-risk dish, a missed one (low recall) is the dangerous error. If it is used to count servings for ordering, both directions distort the counts, so look at both, and at where the mistakes go: the confusion matrix shows bread pudding's misses are spread across all three other dishes.
Averages, and the accuracy paradox
Accuracy is the share of all predictions that are correct: 142/160 = 88.75%. To summarise per-class metrics in one number:
- a macro average takes the plain mean over classes (every dish counts equally);
- a weighted average weights each class by how many examples it has.
With 40 photos per dish these are identical (0.8875). With imbalance they diverge sharply. Suppose 95 trays are a common dish and 5 a rare one, and the model always says "common":
accuracy 0.95 recall on the rare dish 0.00 macro F1 0.49
95% accurate, and useless for the rare dish. Real menus are imbalanced: some dishes appear every day, others once a week. A hospital evaluation should therefore report per-dish recall and precision, not only overall accuracy. This is the most common way a headline accuracy figure misleads.
3. Thresholds: one model, many trade-offs
A classifier outputs scores; a threshold turns scores into decisions. Moving the threshold trades one error for another, without changing the model.
Worked example: one model, eight trays, many thresholds
Take a yes/no question: "will this tray come back more than half full?" A model gives each tray a score between 0 and 1, and says "yes" when the score is at or above a threshold. Eight trays, four of which really did come back more than half full:
| Tray | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 |
|---|---|---|---|---|---|---|---|---|
| Model's score | 0.90 | 0.80 | 0.70 | 0.60 | 0.40 | 0.35 | 0.30 | 0.10 |
| Really more than half full? | yes | yes | no | yes | no | yes | no | no |
Now slide the threshold down and count. Two rates describe each setting:
- the true positive rate (TPR, the same thing as recall): the share of the 4 real "yes" trays that the model calls "yes";
- the false positive rate (FPR): the share of the 4 real "no" trays that it wrongly calls "yes".
| Say "yes" if score ≥ | Trays called "yes" | True positives | False positives | TPR | FPR | Precision |
|---|---|---|---|---|---|---|
| 0.95 | none | 0 | 0 | 0.00 | 0.00 | – |
| 0.75 | 1, 2 | 2 | 0 | 0.50 | 0.00 | 1.00 |
| 0.65 | 1–3 | 2 | 1 | 0.50 | 0.25 | 0.67 |
| 0.50 | 1–4 | 3 | 1 | 0.75 | 0.25 | 0.75 |
| 0.33 | 1–6 | 4 | 2 | 1.00 | 0.50 | 0.67 |
| 0.00 | all 8 | 4 | 4 | 1.00 | 1.00 | 0.50 |
Read it top to bottom: a lower threshold finds more of the real "yes" trays (recall rises) at the price of more false alarms (precision tends to fall). The model never changed; only the threshold did. Which row is best depends entirely on what a miss and a false alarm each cost.
The ROC curve plots TPR (up) against FPR (across) for every threshold, from (0, 0) at the top of the table to (1, 1) at the bottom. A model that ranks perfectly shoots straight up to TPR 1 before any false positive; a model that guesses runs along the diagonal.
AUC (area under the ROC curve) sums that up in one number, and it has a plain meaning: pick one real "yes" tray and one real "no" tray at random; AUC is the probability the "yes" tray got the higher score. Here there are 4 × 4 = 16 such pairs. Counting the ones ranked correctly: tray 1 beats all four "no" trays (4), tray 2 beats all four (4), tray 4 beats trays 5, 7 and 8 but not 3 (3), tray 6 beats trays 7 and 8 (2). That is 13 of 16: AUC = 0.81. (Measuring the area under the plotted curve gives the same 0.8125.) 0.5 means no better than guessing; 1.0 means every "yes" tray outranks every "no" tray.
Two cautions:
- AUC judges ranking across all thresholds at once. It says nothing about which threshold to use; you still have to choose one for the decision at hand.
- When "yes" cases are rare (say 2% of trays), FPR stays tiny even with many false alarms, so ROC looks flattering. Plotting precision against recall (a precision–recall curve) is then more informative, because precision drops visibly when false alarms swamp the true cases.
TrayCheck's threshold: when to ask a person
TrayCheck uses its threshold differently: below it, the model abstains and a person checks. This is an old idea, known as the reject option, and in deep learning as selective classification. Two numbers describe it:
- coverage: the share of photos accepted without review;
- risk: the error rate among those accepted.
threshold coverage (auto-accepted) error among accepted (160 test photos)
0.50 96.9% 9.0%
0.70 83.8% 4.5%
0.85 76.2% 4.1% ← chosen on validation photos
0.95 58.8% 2.1%
TrayCheck's rule picks the lowest threshold whose error among accepted validation photos is at most 5%. That gave 0.85. On the test photos it delivers 4.1% error at 76% coverage, so the target held on data the choice never saw. Two honest observations:
- On the test photos, 0.80 would have done as well with less review work. You only know that by looking at test data, which is exactly what you mustn't use to choose (Module 9).
- The curve flattens. Past a point, raising the threshold mostly adds review work, because the remaining errors are confident mistakes (scores of 0.87 to 0.99). Those need independent checks, the menu check and random spot checks (Module 11), not a higher threshold.
4. Can the scores be trusted? Calibration
A model is calibrated if its scores mean what they say: among all predictions made with score 0.9, about 90% are right. This matters whenever a score is shown to a person or used to set a threshold. Modern deep networks are often overconfident: their scores run higher than their accuracy.
A reliability table groups predictions by score and compares the average score with the actual accuracy in each group:
| Score range | Photos | Average score | Actual accuracy | Gap | Photos × gap |
|---|---|---|---|---|---|
| 0.25–0.40 | 1 | 0.379 | 0.000 | 0.379 | 0.38 |
| 0.40–0.55 | 8 | 0.495 | 0.375 | 0.120 | 0.96 |
| 0.55–0.70 | 17 | 0.631 | 0.647 | 0.016 | 0.27 |
| 0.70–0.85 | 12 | 0.777 | 0.917 | 0.140 | 1.68 |
| 0.85–1.00 | 122 | 0.970 | 0.959 | 0.011 | 1.33 |
| All | 160 | 4.62 |
The expected calibration error (ECE) is the average gap between score and accuracy, with each
group weighted by how many photos it holds: add up the last column and divide by the number of
photos. 4.62 / 160 = 0.029. TrayCheck is reasonably calibrated: slightly overconfident at the top
(says 97%, right 96%). With 1 to 17 photos in the lower groups, treat their individual gaps as
rough; one photo more or less right moves them a lot. The chart is saved as course/labs/output/lab10_reliability.png.
Temperature scaling: a fix that didn't help here
Temperature scaling divides the model's raw outputs (logits) by one number T before the softmax, with T fitted on validation data. T > 1 softens the scores, T < 1 sharpens them. Because it never changes which dish has the highest score, accuracy is unchanged:
best temperature on validation: T = 1.15
test log-loss: before 0.304 after 0.305
test ECE: before 0.029 after 0.039
test accuracy: before 0.8875 after 0.8875
It made test calibration slightly worse. Validation said "soften the scores", partly because its noisier labels (Module 9) make the model look overconfident there; the cleaner test set didn't need it. The lesson: calibrate on data that resembles deployment, and check the result on held-out data. In a real pilot, the human-reviewed records, especially the random spot checks, would be the right calibration data.
5. Every number needs an error bar
A test set is a sample, so every metric computed on it is an estimate. If you tested a different 160 photos you would get a somewhat different number.
The quick version (built step by step in Module 2 §9–§12). Each photo is a yes/no outcome, right or wrong, with spread √(p(1 − p)). Averaging n independent outcomes shrinks that spread by √n, giving the standard error:
For TrayCheck, p = 0.8875 and n = 160, so SE ≈ 0.025. An estimate lands within 1.96 standard errors of the truth in about 95% of samples, so a rough 95% range is p ± 1.96 × SE: about 88.75% ± 4.9 points. With 160 examples, accuracy is known to within about ±5 points.
The better version. The simple formula assumes a symmetric bell shape, which fails near 0% or 100% and for small samples: it can produce ranges below 0% or above 100%. The Wilson interval fixes that, and is what TrayCheck reports. Module 11 §3 explains the idea behind it. TrayCheck's numbers:
overall accuracy 142/160 = 88.8% 95% interval 82.9% to 92.8%
recall, ribs 36/40 = 90.0% 95% interval 76.9% to 96.0%
recall, bread pudding 33/40 = 82.5% 95% interval 68.0% to 91.3%
The per-dish intervals overlap heavily. With 40 photos per dish you can't claim bread pudding is genuinely harder than ribs, only that it did worse in this sample. Saying this unprompted in an interview shows real statistical maturity.
How many trays does a PoC need to check?
Rearranging the same formula answers a planning question: to measure an accuracy near 90% to within a margin E (95% confidence), you need about
| Margin wanted | Trays to check (at ~90% accuracy) |
|---|---|
| ± 5 points | about 140 |
| ± 3 points | about 385 |
| ± 2 points | about 865 |
Those numbers apply per group you want to report. If the PoC needs accuracy per dish to within ±5 points, it needs about 140 checked trays of each dish, which rare dishes may never reach during a short pilot. This is worth raising when the test plan is written, not after.
6. Evaluating amounts: portion and waste estimates
Food and waste amounts are numbers, not categories, so classification metrics don't apply. The standard way to compare a new measurement method with a reference method is borrowed from clinical measurement, and dietitians will know it.
Suppose a system estimates the grams left on six trays, and the same trays are weighed (made-up numbers, for illustration only):
| Tray | Weighed (g) | AI estimate (g) | Difference (AI − weighed) |
|---|---|---|---|
| 1 | 120 | 135 | +15 |
| 2 | 80 | 70 | −10 |
| 3 | 200 | 230 | +30 |
| 4 | 0 | 15 | +15 |
| 5 | 150 | 160 | +10 |
| 6 | 60 | 50 | −10 |
Four numbers describe the agreement:
- Bias (mean difference): add the differences and divide by 6: 50 / 6 = +8.3 g. On average the system overestimates waste. Over a service this adds up: 660 g estimated vs 610 g weighed, 8% too high.
- Mean absolute error (MAE): drop the signs and average: (15 + 10 + 30 + 15 + 10 + 10) / 6 = 15 g. The typical size of a miss, ignoring direction.
- Root mean squared error (RMSE): square each difference, average, then take the square root: √((225 + 100 + 900 + 225 + 100 + 100) / 6) = √275 = 16.6 g. Like MAE, but squaring makes large misses count for more (the 30 g miss contributes 900 of the 1,650).
- 95% limits of agreement: bias ± 1.96 × (standard deviation of the differences). The standard deviation of these six differences is 15.7 g (Module 2 §9 computes it step by step), so the limits are 8.3 ± 1.96 × 15.7 = −22 g to +39 g. For an individual tray, the estimate can be expected to fall anywhere from 22 g too low to 39 g too high. The 1.96 is the same "middle 95%" distance as in §5.
This last idea is the Bland–Altman method, the standard way in clinical measurement to judge whether two measurement methods agree well enough to be used interchangeably. Plot the difference against the average of the two measurements to see whether errors grow with portion size, a common pattern.
Interpretation is a judgement about the decision. Limits of ±30 g might be fine for ward-level waste trends over a month, where individual errors average out (though the bias does not). They may be too wide for tracking an individual patient's intake, which a dietitian might need within a few grams. Same numbers, different verdicts.
7. Look inside the errors: error analysis and slices
A single score hides where the model fails. Two habits find it:
- Error analysis: read the mistakes themselves. TrayCheck's five confident mistakes include three photos wrongly called bibimbap (at 99.0%, 95.6% and 86.6%). That pattern, plus bibimbap's low precision, suggests the model treats "mixed dish in a bowl" as bibimbap. A pattern like that points to a fix: more varied training photos of the other dishes.
- Slice-based evaluation: report metrics per subgroup that matters, such as dish, ward, meal period, camera or lighting. An overall number can hide one failing slice, for example a ward whose trays are photographed under poor light.
Two timescales of evaluation:
- Offline: metrics on a fixed test set, before deployment (everything above).
- Online: metrics from the system in use. In TrayCheck these are the correction rate among reviewed trays, the spot-check error estimate and the off-menu alerts. Online metrics measure the system on the real distribution, which offline tests can only approximate (Module 9).
8. Translating metrics for operational staff
The position description asks you to "translate technical outputs into meaningful operational insights". A useful pattern: metric → what it means per service → what to do about it.
| Metric | Plain-language version | So what? |
|---|---|---|
| Error among auto-accepted trays: 4.1% at 76% coverage | In a service of 500 trays, about 380 are accepted without review and about 16 of those carry the wrong dish | Waste-per-dish reports have a small, known error; spot checks estimate it as the system runs |
| Bread pudding recall: 82.5% | About 1 in 6 bread puddings is recorded as another dish | Bread pudding's waste is under-counted and other dishes' over-counted |
| Bibimbap precision: 86% | About 1 in 7 trays recorded as bibimbap is something else | Bibimbap counts are inflated; check before using them for ordering |
| Accuracy 88.75%, range 83%–93% | Roughly 9 in 10 trays are named right; with 160 test photos we can't be more precise than that | Don't compare models or sites on differences of a few points without more data |
| Waste bias +8 g per tray (illustrative) | The system reads about 8% more waste than the scale | Fine for spotting trends; correct for the bias before reporting totals |
Keep the statistical caveat, but put it second: lead with what the number means for the kitchen.
Check your understanding
1. Using the confusion matrix, compute precision and recall for bread pudding.
TP = 33. Its column sums to 3 + 1 + 2 + 33 = 39, so FP = 6 and precision = 33/39 = 0.846. Its row sums to 40, so FN = 7 and recall = 33/40 = 0.825.
2. A model is 99% accurate at detecting a condition that affects 1% of people. Is that good?
Not necessarily: always predicting "no condition" scores 99% with zero recall. Look at recall and precision for the rare class, or a macro average.
3. Before a PoC test starts, what four things should be agreed in writing?
The decision the results will inform; the ground truth to compare against (and how reliable it is); the metric and the target value; and the test set (which trays, how many, from where and when). Also the baseline (current practice) and the relative cost of each type of error.
4. What does it mean that a model is overconfident, and how would you check?
Its scores are higher than its actual accuracy: among predictions with score about 0.9, fewer than 90% are right. Check with a reliability table or diagram and the expected calibration error, on held-out data that resembles deployment.
5. Temperature scaling changes the scores. Can it change accuracy?
No. Dividing all logits by the same positive number keeps their order, so the top dish never changes. Only the confidence values change.
6. Why can't a higher threshold catch the 99% ribs-called-bibimbap mistake, and what does?
Its score is 0.99, above any threshold that doesn't send nearly everything to review. Independent signals catch it instead: the menu check (if bibimbap isn't being served), a random spot check, or a person who notices while saving.
7. A pilot wants per-dish accuracy to within ±5 points. Roughly how many checked trays does that take?
About 140 per dish at accuracy near 90%, from n ≈ 1.96² × 0.9 × 0.1 / 0.05². For 20 dishes that's about 2,800 checked trays, so either the pilot must be long enough or results should be reported for the most common dishes only, with wider ranges for the rest.
8. An AI waste estimate has bias +2 g and 95% limits of agreement −60 g to +64 g against weighing. Is it good enough?
It depends on the use. On average it is nearly unbiased, so totals over many trays will be close to weighed totals: probably fine for monthly waste trends. But any single tray can be 60 g off in either direction, which is too imprecise for monitoring an individual patient's intake.
Go deeper
Short on time? The study guide says which of these to read first.
Core (free)
- Google Machine Learning Crash Course, Classification module: the pages on thresholds and the confusion matrix, accuracy, precision and recall and ROC and AUC. About 1.5 hours with the exercises; the clearest short treatment.
- scikit-learn User Guide, §3.4 Metrics and scoring: the classification metrics part, including multiclass averaging and the regression metrics (MAE, RMSE). scikit-learn.org/stable/modules/model_evaluation.html
- Guo, Pleiss, Sun & Weinberger (2017), On Calibration of Modern Neural Networks: §1–3 (what calibration is, how to measure it, why modern networks are overconfident) and §4.2 (temperature scaling). arxiv.org/abs/1706.04599
Optional
- ISLP §4.4.2: the credit-default example works through a confusion matrix, changing the threshold and the ROC curve on real data. Free at statlearning.com.
- scikit-learn User Guide, §1.16 Probability calibration. scikit-learn.org/stable/modules/calibration.html
- Bland & Altman (1986), Statistical methods for assessing agreement between two methods of clinical measurement, The Lancet 1(8476): 307–310. The original limits-of-agreement paper, short and readable.
- Brown, Cai & DasGupta (2001), Interval Estimation for a Binomial Proportion, Statistical Science 16(2): why the simple ± formula misbehaves and what to use instead (§1–2 are enough).
- Bishop, Pattern Recognition and Machine Learning, §1.5 Decision Theory, including §1.5.3, the reject option. Free PDF from Microsoft Research.
- Geifman & El-Yaniv (2017), Selective Classification for Deep Neural Networks, NeurIPS.
- Huyen, Designing Machine Learning Systems (2022), Chapter 6, Model Development and Offline Evaluation: baselines, perturbation tests, calibration and slice-based evaluation. Paid.
Interview angle
"When I evaluate a model I agree four things first: the decision it supports, the ground truth, the metric with a target, and the test set. For TrayCheck, accuracy is 88.75% on 160 held-out photos, about 83 to 93% with a 95% interval, so I wouldn't over-read differences between dishes; the per-dish intervals overlap. Per dish, bread pudding has the lowest recall, about 1 in 6 is recorded as something else, and bibimbap the lowest precision, so its counts are inflated.
The review threshold is a precision-for-effort trade-off: I chose 0.85 on validation photos to keep errors among unreviewed trays under 5%, and on test it gave 4.1% with about three quarters of trays needing no review. The remaining errors are confident ones, so a higher threshold won't catch them; random spot checks estimate how many there are.
For portion or waste estimates I'd compare against weighed trays and report bias, mean absolute error and Bland–Altman limits of agreement, because whether ±30 grams is good enough depends on whether it's for ward trends or an individual patient."