Artificial Intelligence · AI Foundations
Evaluating AI Systems
In AI because the evaluation, not the model, is what decides whether an intelligent system may ship — and designing one is a skill of its own.
Every serious AI team maintains two artefacts: the model and the evaluation that decides whether the model may ship — and of the two, the evaluation is the one that must be right first. This lesson builds that artefact from its parts: what a metric is, why accuracy collapses on rare events, what precision and recall each measure, why one overall number always hides its slices, and what happens to any metric the moment it becomes a target.
- Artificial Intelligence
- Medium level
- 6 concepts
1Evaluation from day one
A model without a metric is a demo, not a decision system. A metric is a number, named before the model is built, that is computed by comparing predictions against answers the model was never shown — and 'named before' is doing real work in that sentence, because a metric chosen after the results are in tends to be the one the results happen to flatter.
Real systems run two evaluations, not one. Offline metrics are computed on a frozen, held-out dataset before anything ships: they are cheap, repeatable, and safe to fail. Online metrics are measured on live traffic after deployment — task success, complaint rates, revenue — and they are the ones the organisation actually cares about.
The offline metric is a proxy for the online one, and the gap between them is where evaluation goes wrong: a system can score beautifully on a fixed test set and still lose its users, because the test set stopped resembling the traffic. Strong teams treat the eval suite as a product of its own — versioned, reviewed, and extended every time a failure reaches production that the suite failed to predict.
The design order is therefore fixed: state the decision the system makes, choose the offline metric that best predicts the online outcome of that decision, freeze the held-out data — and only then fit a model.
Figure. One loop, two measurements. The offline eval on frozen data decides whether a candidate may ship; the online metrics on live traffic decide whether it should stay. Every online failure the offline suite did not predict becomes a new offline test — that dashed edge is how an eval suite grows.
Designing an eval
- Name the decisionWrite down what the system decides and for whom — flag this transaction, rank this answer, admit this patient.
- Pick the proxyChoose the offline metric most likely to move with the online outcome, and record why you believe it will.
- Freeze the holdoutSet aside test data the fit never touches; every reuse of it spends a little of its honesty.
- Wire the live checkDecide what will be measured after deployment, and what number triggers a rollback.
A classmate demos a model that 'looks right on the examples we tried'. What is missing before it is a decision system rather than a demo?
- A stated metric, measured on cases that were not used to build it
- A larger training set, so the examples are more representative
- A deeper architecture, so the model has capacity to spare
- A user interface for entering the examples more quickly
Examples chosen by the builder cannot fail. A metric names in advance what counts as working, and unseen data is what stops the answer being rehearsed.
2Accuracy and the do-nothing floor
Accuracy is the fraction of predictions that are correct; error rate is its complement. It is the first metric everyone learns and the only one many systems ever report, so its failure mode needs to be understood precisely rather than vaguely distrusted.
Accuracy weights every row equally. That is fine when the classes are balanced and the two mistakes cost the same; it is catastrophic when one class is rare, because a model can then buy a high score by ignoring the rare class completely.
Before admiring any accuracy figure, compute the do-nothing floor: the score of the constant model that predicts the majority class for every row. On a dataset of 1,000 payment transactions of which 10 are fraudulent, that floor is 99% — any reported accuracy has to be read against it, not against zero.
The floor is not a straw man. It is the model you get for free, with no data, no training and no failure modes — so it is the price any learned model must beat before it has earned anything.
Figure. The whole dataset as one bar, segments drawn to scale. The sliver at the end is the fraud — 1% of the rows and 100% of the reason the system exists. Accuracy scores the bar by length, so a model that ignores the sliver still scores 99%.
Scoring the model that does nothing
1,000 transactions, 10 fraudulent. The constant model predicts 'legitimate' for every row.
- Correct predictions = all 990 legitimate rows990 of 1,000
- Accuracy = 990 / 100099%
- Error rate = 1 − 0.991%
- Verdict on a model reporting 98.5%worse than doing nothing
Pro tip. The floor moves with the base rate: at 1 fraud per 1,000 it is 99.9%. The rarer the event, the more impressive accuracy sounds and the less it means.
3Class imbalance: when accuracy lies
Class imbalance is the situation where the outcomes you care about are rare: fraud in payments, disease in screening, defects on a production line. It is the normal case in deployed AI, not the exception, and it is exactly where accuracy stops measuring usefulness.
The mechanism deserves a precise statement: accuracy rewards a model for ignoring the rare class entirely, because every rare row sacrificed buys the model 99 easy ones. The optimisation pressure and the purpose of the system point in opposite directions.
The repair is to score the rare class directly, with two questions that have two different denominators: of the real frauds, what fraction did the model catch — and of the rows the model flagged, what fraction were really fraud. The precision-and-recall concept names and formalises both; here the point is only that neither can be bought by ignoring the sliver.
The confusion matrix is the bookkeeping device that makes the failure visible: four cells counting each way a prediction can meet reality. Below, the do-nothing model's 99% collapses into its cells — the entire score lives in one box, and the 10 rows that mattered sit in another.
Figure. The do-nothing model's whole 99% sits in the top-left cell. The 10 rows the system exists for sit beside it, missed; both cells in the calling-fraud row hold zero. Accuracy adds along the diagonal, so it cannot see which cell the correctness came from.
Where the 99% lives
The do-nothing model on the 1,000-transaction set: 990 legitimate, 10 fraud, everything predicted 'legitimate'.
- Legit called legit (true negatives)990
- Fraud called legit (false negatives)10
- Fraud called fraud (true positives)0
- Fraud recall = 0 / 100%
Pro tip. Read a confusion matrix by rows of reality: the frauds live in one row, and any model whose caught-fraud cell is zero is not a fraud detector, whatever its accuracy.
Coding lab. Accuracy vs recall on imbalanced data runs in the app, with checks on your output.
4Precision, recall and F1
Precision and recall put denominators under the two questions that class imbalance forces. Recall — of the rows that are truly positive, what fraction did the model flag — is computed against reality's total. Precision — of the rows the model flagged, what fraction are truly positive — is computed against the model's own flag count. Same confusion cells, different denominators, and confusing the two is the most common metrics error in practice.
The two trade against each other through the flagging behaviour: flag more rows and recall rises while precision falls; flag fewer and the reverse. Neither is 'the' metric — the task's costs decide which failure is dearer, which is the subject of the cost-sensitive lesson that follows this one.
F_1 is the harmonic mean of the pair, F_1 = 2PR/(P+R). The harmonic mean is chosen because it is dragged toward the smaller value: a model cannot hide a terrible precision behind a perfect recall, where an ordinary average would let it.
F1 also treats precision and recall as equally important, which is itself an assumption about costs — a silent one. Report the pair; reach for F1 when you need a single number to rank models by and have no cost model yet.
Figure. The same model as three numbers. The harmonic mean (F1 = 0.32) sits near the weaker of the pair; the arithmetic mean would sit at 0.50 and hide the precision problem entirely.
One model, three numbers
On the 1,000-transaction set a trained model flags 40 rows; 8 of the 10 real frauds are among them.
- Recall = 8 / 100.80
- Precision = 8 / 400.20
- F1 = 2 × 0.80 × 0.20 / (0.80 + 0.20)0.32
- Arithmetic mean, for contrast0.50 — flattering, and wrong to use
Pro tip. Precision uses the model's own flag count as its denominator, so it can be gamed by flagging almost nothing. Recall's denominator is fixed by reality. When someone quotes only one of the pair, ask what the other was.
5Slice metrics: one average hides many systems
Every overall metric is a weighted average over segments of traffic — devices, regions, languages, customer tenures — and the model is not equally good on all of them. Slice metrics are the same metric computed per segment, and they are how real evaluation suites are organised: the overall number decides nothing on its own.
The arithmetic makes the hiding mechanical: a segment that is 10% of the data contributes 10% of the average, so the model can be near-useless there while the headline barely moves. The users in that slice do not experience an average.
A slice regression is also how models fail in production most often: an update improves the majority slice, the overall metric climbs, and a minority slice quietly breaks. An eval that tracks only the overall number will approve exactly that update.
Slicing is also where evaluation meets fairness: subgroup performance gaps are slice metrics by another name — that thread continues in the ethics and governance lesson.
Figure. The overall bar sits comfortably next to desktop while mobile fails at a coin flip — 10% of the traffic moves the average by only 4.5 points. The average is not evidence about any slice.
A 90.5% that is two different models
A model scores 95% accuracy on 900 desktop sessions and 50% on 100 mobile sessions.
- Desktop correct = 0.95 × 900855
- Mobile correct = 0.50 × 10050
- Overall = (855 + 50) / 100090.5%
- What a mobile user experiencesa coin flip
Pro tip. Decide the slices before the eval runs — the segments you would be embarrassed to fail on — and give each slice its own bar to clear. Slices invented after a bad result have a way of being the ones that look fine.
6Goodhart's law: when the metric becomes the target
Goodhart's law is the observation that a measure that becomes a target stops being a good measure. In ML systems it has two distinct faces, and both will happen to you.
The first face is the model gaming the metric: optimisation finds the cheapest way to the number, not the intended behaviour. Trained on click-through, a recommender learns clickbait; trained to close support tickets fast, a triage system learns to close them unsolved. The metric was a proxy, and optimisation pressure finds the gap between proxy and goal.
The second face is the team gaming the eval: every time a decision is tuned by looking at the test set — a threshold nudged, a feature kept because the held-out score liked it — a little of the set's independence is spent. Enough peeks, and the 'held-out' score is a training score wearing a lab coat.
The defences are structural, not moral: keep a final holdout that nobody tunes against, refresh eval data on a schedule, watch counter-metrics chosen to move if the proxy is being gamed, and treat any metric that improved suspiciously fast as a bug until traced.
The picture this concept wants is two curves parting company: the reported metric climbing steadily while the quantity it was meant to stand for sinks — the gap between them is what optimisation pressure found. The counter-metrics table gives three real instances of that gap.
Each proxy invites a specific cheat, and each cheat has a number that catches it.
| Metric targeted | The cheap way to it | Counter-metric to watch |
|---|---|---|
| Click-through rate | Clickbait that disappoints on arrival | Dwell time after the click |
| Tickets closed per hour | Closing without solving | Reopen rate |
| Test-set accuracy | Tuning against the test set until it flatters | A final holdout nobody may tune on |
Notes
- Metrics before models: offline proxies, the do-nothing floor, precision/recall, slices and Goodhart's law.
- A model without a metric is a demo, not a decision system.
- On rare-event data, accuracy can be 99% while the model catches nothing.
Formulas
- Accuracy = correct / total
- Recall = TP / (TP + FN)
- Precision = TP / (TP + FP)
- F_1 = 2PR/(P+R)
Exam traps & shortcuts
- Compute the do-nothing baseline before admiring any accuracy figure — on rare-event data it is usually above 99%.
- Never tune against the test set; a metric you optimised is no longer a measurement.
- One overall number always hides its slices — check the metric per segment before shipping.
Reference tables
The working metrics of this lesson, each with the question it answers and the situation in which it stops answering it.
| Metric | Question it answers | Fails when |
|---|---|---|
| Accuracy | What fraction of all predictions are right? | Classes are imbalanced or error costs differ |
| Recall | What fraction of the real positives were caught? | Used alone — flag everything and it is perfect |
| Precision | What fraction of the flagged rows are real? | Used alone — flag one sure case and it is perfect |
| F1 | One number when precision and recall both matter | Costs are asymmetric; it silently weights them equally |
| Calibration | Do predicted probabilities match observed frequencies? | The model ranks well but its probabilities overstate certainty |
Recap
This lesson in brief:
- Evaluation from day one
- Name the metric and freeze the holdout before the model exists; offline scores are proxies for online outcomes.
- The do-nothing floor
- Score the constant majority-class model first — on rare events that floor starts near 99%.
- Precision and recall
- Recall counts caught positives over reality's total; precision over the model's flag count; F1 leans toward the weaker of the two.
- Slices and gaming
- One average hides its slices, and any metric that becomes a target invites the cheapest path to it.
Practise Evaluating AI Systems
Reading is free and needs no account. Practice, mocks and progress live in the app.
- A 1-question practice set that ends the chapter
- 1 quick check with worked explanations
- Timed mocks scored with the real marking scheme
- Readiness tracked per topic, kept on your device