LSMA

LONDON SCHOOL OF MULTIOMICS & AI

Free course

Free course

0 of 11 lessons

Lesson 1 of 2

Module 2 · Judging a model

Measuring performance

Measuring performance

Measuring performance

“95% accurate” tells you almost nothing about a medical test. This lesson gives you the numbers that do, and shows why the same model can be excellent in one setting and misleading in another.

⏱ 12 min readModule 2 · Judging a modelFree
Lesson at a glance3 steps · about 12 min
  1. Four outcomes
  2. One threshold, or all of them
  3. Calibration: can you trust the percentage?

Four outcomes

Module 1 ended with a finished model and a locked test set. This module asks what the results on that test set mean, and how much they can be trusted. This lesson turns the model's answers into the figures you will meet in every paper and product leaflet; the next, Evidence: from validation to trials, asks what kind of study those figures came from.

A true positive flags a sick patient; a false positive flags a healthy one. A true negative clears a healthy patient; a false negative misses a sick one.

"Positive" here means only that the model raised a flag, and "negative" that it did not; neither word says anything about whether the result was good news. "True" and "false" say whether the flag agreed with the reference standard, the best available answer, such as a confirmed diagnosis. The four outcomes are often abbreviated TP, FP, TN and FN, and arranged in a two-by-two grid called a confusion matrix: one column for patients who have the disease, one for those who do not, one row for flagged and one for cleared.

Each kind of error has its own cost. For a sepsis alert, a false negative may mean delayed antibiotics; a false positive means a nurse's time, and perhaps an unneeded blood test. Deciding which error matters more is a clinical judgement, not a statistical one.

The same model can be used in ways that weigh the errors very differently. As a screening tool that sends people for a further test, a false positive costs one extra appointment, so many can be tolerated. As a tool that rules people out and sends them home, a false negative may mean a missed cancer or heart attack, so very few can be tolerated. Before reading any figures, it helps to write down what the tool will be used for and what each kind of error would cost in that use.

How to read the table below

Each measure is a fraction made from the four outcomes. Sensitivity and specificity start from the truth: they take the sick, or the healthy, and ask how the model treated them. The two predictive values start from the model's answer: they take everyone flagged, or everyone cleared, and ask how many were right. That difference turns out to matter a great deal.

MeasureQuestion it answersFormula
SensitivityOf the sick, how many does it catch?TP ÷ (TP + FN)
SpecificityOf the healthy, how many does it clear?TN ÷ (TN + FP)
Positive predictive valueIf it says positive, how likely is disease?TP ÷ (TP + FP)
Negative predictive valueIf it says negative, how likely is health?TN ÷ (TN + FN)

For example, if 20 patients on a ward have a condition and a model flags 18 of them, the sensitivity is 18 ÷ (18 + 2) = 90%. Sensitivity and specificity stay roughly the same wherever the model is used, provided the patients and data are alike. The predictive values do not: they depend on prevalence, the proportion of people in the tested group who have the disease. The worked example shows how strongly.

Any figure measured on a sample is an estimate, and a small sample gives an uncertain one. Eighteen out of 20 is 90%, but with only 20 sick patients the true sensitivity could plausibly be anywhere from about 70% to 97%. Papers show this with a confidence interval, a range of values consistent with the data. A pitfall is to compare two models on their headline figures alone: if their intervals overlap widely, the test set may simply be too small to say which is better.

The word "roughly" above also hides a caveat. Sensitivity depends on how hard the cases are. A model tested mostly on obvious, advanced disease will find more of it than a model tested on early, subtle disease, even if they are the same model. This is called spectrum bias. When a paper reports high sensitivity, check whether the sick patients in the test set look like the ones the tool would meet in use.

Worked example · the prevalence trap

A screening model with 90% sensitivity and 90% specificity screens 10,000 people, 1% of whom have the disease.

with disease: 100 → catches 90 (TP), misses 10 (FN)
without: 9,900 → clears 8,910 (TN), flags 990 (FP)
PPV = 90 ÷ (90 + 990) = 8%

The same model in a specialist clinic where 20% have the disease:

with disease: 2,000 → TP 1,800, FN 200
without: 8,000 → TN 7,200, FP 800
PPV = 1,800 ÷ (1,800 + 800) = 69%

Same model, very different meaning. Always ask what the prevalence was where a model was tested, and what it will be where you use it.

Step by step, screening. 1% of 10,000 = 100 people with the disease, leaving 9,900 without. Sensitivity 90%: 90% of 100 = 90 caught, so 10 missed. Specificity 90%: 90% of 9,900 = 8,910 cleared, so 9,900 − 8,910 = 990 healthy people flagged. Everyone flagged: 90 + 990 = 1,080. PPV = 90 ÷ 1,080 = 0.083, about 8%.

Step by step, clinic. 20% of 10,000 = 2,000 with the disease and 8,000 without. 90% of 2,000 = 1,800 caught, 200 missed. 90% of 8,000 = 7,200 cleared, 800 flagged. Everyone flagged: 1,800 + 800 = 2,600. PPV = 1,800 ÷ 2,600 = 0.69, about 69%.

What the answer means. In screening, about 11 of every 12 people flagged are healthy, because 10% of a very large healthy group (990) far outnumbers 90% of a small sick group (90). The negative predictive value moves the other way: in screening it is 8,910 ÷ 8,920, about 99.9%, and in the clinic 7,200 ÷ 7,400, about 97.3%. A negative result is most reassuring where the disease is rare. When a tool moves from a specialist clinic to a general population, expect many more false alarms per true case, even though the model has not changed at all.

Measuring performance · LSMA free course Two two-by-two tables for the same model with 90 percent sensitivity and specificity. In screening at 1 percent prevalence: 90 true positives, 990 false positives, 10 false negatives and 8,910 true negatives, so only 8 percent of flagged people are sick. In a specialist clinic at 20 percent: 1,800 true positives, 800 false positives, 200 false negatives and 7,200 true negatives, so 69 percent of flagged people are sick. 1 · SCREENING, 1% PREVALENCE has diseaseno disease flaggedcleared TP 90 FP 990 FN 10 TN 8,910 PPV = 90 ÷ 1,080 = 8% flagged: 90 sick · 990 healthy 2 · CLINIC, 20% PREVALENCE has diseaseno disease flaggedcleared TP 1,800 FP 800 FN 200 TN 7,200 PPV = 1,800 ÷ 2,600 = 69% flagged: 1,800 sick · 800 healthy
The model is identical in both panels; only the mix of patients changes. The bar under each table shows everyone the model flagged: the green part is the people who are sick. At 1% prevalence, the false positives from the large healthy group swamp the true ones. Numbers from the worked example above.

One threshold, or all of them

Most models output a score, and a threshold turns it into yes or no. Lowering it catches more disease but raises false alarms. The ROC curve shows the trade-off at every threshold, and the area under it (AUC) summarises it: 0.5 is a coin toss, 1.0 is perfect.

Think of the score as a risk between 0 and 1. With a threshold of 0.5, only patients scoring above 0.5 are flagged. Move it down to 0.2 and more patients are flagged: some of the extra ones are sick (sensitivity rises), and some are healthy (specificity falls). No threshold removes both kinds of error; choosing one means choosing which error you would rather make.

In practice the threshold is often chosen in one of three ways. The team may fix a target sensitivity, for example "miss no more than 5% of cases", and accept whatever specificity follows. They may fix a workload, for example "no more than 30 alerts a day", and accept whatever sensitivity follows. Or they may pick the threshold at which the model's risk matches the point where clinicians would act anyway. Whichever is chosen, it should be set before the final test and reported, because a threshold chosen afterwards to make the results look good is another way of tuning on the test set.

ROC stands for receiver operating characteristic, a name from early radar research. The curve plots sensitivity on the vertical axis against the false positive rate (1 − specificity) on the horizontal axis, one point for each possible threshold. The AUC has a useful plain meaning: if you pick one patient with the disease and one without at random, the AUC is the chance that the model gives the sick patient the higher score. An AUC of 0.8 means it ranks such a pair correctly 80% of the time.

A pitfall with rare outcomes is that the ROC curve can look excellent while the tool still produces mostly false alarms. The horizontal axis is a rate among the healthy, and when the healthy group is huge, even a small rate is a large number of people. For this reason, many AI papers also show a precision-recall curve. The words come from computer science: precision is the positive predictive value, and recall is sensitivity. That curve shows directly how often a flag is right at each level of sensitivity, so it gives a more honest picture when the outcome is rare.

0.00.51.00.00.51.0False positive rateTrue positive rateMulti-omics modelAUC 0.86 Clinical onlyAUC 0.69
The curve that bows further to the top left ranks patients better. Illustrative data.

Reading the figure. The bottom-left corner is a threshold so high that nobody is flagged; the top-right corner is one so low that everybody is. The diagonal from corner to corner is what guessing would achieve. The closer a curve comes to the top-left corner, where sensitivity is 100% and the false positive rate 0%, the better the model separates the two groups. The usual mistake is to stop at the AUC: it describes all thresholds at once, but in practice you will use one, so ask for sensitivity and specificity at that threshold.

Go deeper: what a threshold says about values

Choosing a threshold is also a statement about how much each error matters. Suppose a clinic treats everyone whose risk is above 10%. At exactly 10%, out of ten such patients one will have the disease and nine will not. Treating all ten means accepting nine unneeded treatments to help one person, so the clinic is saying a missed case is about nine times worse than an unneeded treatment.

Decision curve analysis, described by Vickers and Elkin in 2006, turns this into a single figure called net benefit: true positives minus false positives weighted by those odds. Say a model flags 8 sick and 20 healthy patients out of every 100 at the 10% threshold. Net benefit is 8 − 20 × (1 ÷ 9) ≈ 5.8 per 100. That is as useful as finding 5.8 true cases per 100 with no false alarms, and it can be compared directly with treating everyone or no one.

Calibration: can you trust the percentage?

If a model says 30% risk, about 30 of every 100 such patients should have the outcome. That is calibration. A model can have a high AUC and still be badly calibrated, which matters whenever the number guides a decision.

The two ideas measure different things. AUC asks whether sicker patients get higher scores than less sick ones: it is about order. Calibration asks whether the scores mean what they say: it is about size. Suppose a model gives every patient exactly double their true risk. It still ranks them in the right order, so its AUC is unchanged, but a patient told "40%" really has a 20% risk. If a clinic offers a preventive drug to everyone above 30%, that model would treat many people who do not meet the rule.

Calibration often slips when a model moves to a new population with a different rate of the outcome. It can be checked on local data, and corrected by recalibration, which adjusts the scores without retraining the whole model.

Two simple summaries describe calibration. Calibration-in-the-large compares the average predicted risk with the actual rate of the outcome: if a model predicts 10% on average and 15% of patients have the outcome, it underestimates risk overall. The calibration slope describes whether predictions are too extreme or too modest. A slope below 1 means the predictions are spread too widely, too low at the bottom and too high at the top, which is a typical sign of the overfitting you met in How a medical AI model is built. A slope above 1 means they are bunched too closely together.

When does calibration matter most? Whenever the number itself is shown to a clinician or patient, or compared with a fixed rule such as "offer treatment above 10%". It matters less when the model is used only to sort a list, for example to decide which scans a radiologist reads first, because then only the order counts.

0.00.51.00.00.51.0Predicted riskObserved rateWell calibratedMatches reality OverconfidentExtremes overstatedDashed line:perfect calibration
A well calibrated model follows the diagonal; an overconfident one overstates the extremes. Illustrative data.

Reading the figure. Patients are grouped by their predicted risk, for example all those given 20 to 30%. For each group, the horizontal position is the average predicted risk and the vertical position is how often the outcome actually happened. A point on the diagonal means prediction and reality agree. An overconfident model predicts risks that are too extreme: too low for low-risk patients and too high for high-risk ones.

For a readable account of why calibration matters, cite Van Calster and colleagues, "Calibration: the Achilles heel of predictive analytics" (BMC Medicine, 2019). They argue that poor calibration can make a model's risks misleading even when its AUC is high, and that calibration should be checked whenever a model is moved to a new setting. One caveat when you check it yourself: a calibration plot drawn from a small local sample, with few patients who had the outcome, is noisy. Apparent miscalibration may be chance, so judge the plot alongside its uncertainty and the number of outcomes behind it.

Key point

Ask for sensitivity, specificity, PPV at your prevalence, and calibration. One accuracy figure or AUC is never enough.

A second example of why: accuracy is the share of all patients classified correctly. If 5% of patients have a condition, a "model" that says "no" to everyone is right about the other 95%, so it is 95% accurate, while its sensitivity is 0%. A headline accuracy figure can hide a tool that never finds a single case.

The next lesson moves from the figures to the studies that produce them. The same sensitivity can come from a careful study at several hospitals or from a single convenient dataset, and the difference matters as much as the number itself.

Further reading · Module 2Trevethan 2017: sensitivity, specificity and predictive values, with their pitfalls. · All reading for this course

Check your understanding

1. A model catches 45 of 50 patients with sepsis. Its sensitivity?

2. A model moves from a specialist clinic to population screening. What happens to its PPV?

3. What does an AUC of 0.5 mean?

Up next

Lesson 2

Evidence: from validation to trials

Ask BioTutor

Create a free website with Framer, the website builder loved by startups, designers and agencies.