Guide · Prediction · 15 sections

Prediction and Model Validation

A worked guide to defining a prediction target, developing a model, validating its probabilities and choosing a follow-up threshold.

No account needed to read online.

Would you deploy this risk model?

A team can follow up 40 of every 100 people. A model estimates 30-day event risk using information available at enrollment. Validate its predictions in two illustrative cohorts of 100 people, with 20 people at each score.

First, try a 30% threshold and count who qualifies. Then raise it one step. Once the 40 places are filled, compare predicted and observed events in each cohort.

Reveal the answer and interpretation

At a 40% threshold, the two highest score groups qualify: 20 people in each group. The model expects 8 + 10 = 18 events among them. In the original cohort, 18 events occur. Switch to the later cohort to see whether the forecast still holds.

Calibration by risk group

0%0%20%20%40%40%60%60%Observed riskPredicted risk
Each dot represents 20 people. The dashed line marks perfect agreement.
PredictedObservedEvents / N
10%10%2 / 20
20%20%4 / 20
30%30%6 / 20
40%40%8 / 20
50%50%10 / 20

Choose a follow-up threshold

Select the lowest available threshold that keeps follow-up within capacity. People at or above your threshold receive follow-up.

People flagged60 / 100
Events captured24 / 30
Events missed6
Sensitivity80%
Positive predictive value40%
Interpret this validation

The observed proportions match the scores in this constructed cohort. Switch to the later cohort and examine whether the same scores still mean the same absolute risks.

Can better probabilities leave the ranking unchanged?

Keep the same 100 people and outcomes. Compare the original scores with a version that adds 10 percentage points to every prediction. Before switching, predict which will change: the expected event count, the ranking, or both.

Score comparison within the selected cohort
Expected / observed events30 / 30
Discrimination (AUC)0.690
Mean squared probability error (Brier score)0.190

Read chapter 13 on validation · Read chapter 14 on risk and fairness

Reveal the answer and interpretation

Adding the same amount to every score preserves every pairwise ranking, so AUC stays fixed within this cohort. AUC compares a person with an event to one without and gives half credit for tied scores. The Brier score measures probability error against individual outcomes; smaller values indicate better accuracy.

Here the original scores already match all five observed group risks. Adding 10 points raises the forecast from 30 to 40 events when 30 occur. Repeat the comparison in the later cohort.

Read online

Prediction and Model Validation

Contents of the guide
  1. Start with the decision and the prediction clock
  2. Develop a benchmark before a more complex model
  3. The split follows deployment
  4. Where leakage enters
  5. Audit a model whose validation score looks too good
  6. Rebuild the feature pipeline at the decision time
  7. Choose model complexity without spending the test set
  8. Internal validation tests the development process
  9. Which numbers answer which questions
  10. Worked calibration check
  11. Discrimination through a pair of people
  12. Calibration and probability error in the later cohort
  13. Turn a threshold into a decision
  14. Practice: audit your design
  15. Write a validation conclusion

Start with the decision and the prediction clock

A service can offer follow-up to 40 of every 100 people at enrollment. The question is who will experience a defined event within the next 30 days. A predicted risk of 0.40 means that among many comparable people assigned that probability, about 40 in 100 would experience the event if the probabilities were well calibrated. It does not tell us whether follow-up would prevent the event for a particular person.

Write down eligibility, the enrollment date, the event definition, the horizon and what information staff actually have at that date. Decide how the outcome will be ascertained. A person lost after ten days has an unknown 30-day outcome unless another source completes follow-up. Coding that person as event-free changes the target being learned.

Develop a benchmark before a more complex model

A constant-risk model gives everyone the development event rate. A logistic regression adds individual variation: the estimated log odds are an intercept plus a weighted sum of predictors, converted to a probability. A nonlinear model can capture more complex relationships. Compare all candidates using the same eligible records, horizon and evaluation procedure.

Small development samples and many candidate terms can produce unstable probabilities. Penalization shrinks fitted coefficients. Choose its strength inside development resampling, then lock the selected model, preprocessing rules and missing-predictor strategy together. A rule that requires a laboratory measurement at enrollment must also specify what happens when the value is unavailable.

The split follows deployment

If the model will serve future users, reserve a later period for the final test. If customers have repeated records, keep records from the same customer together when estimating performance for new customers. If the model will serve new sites, consider holding out entire sites. Align the split with the deployment scenario instead of relying on a random row split by default.

Where leakage enters

Do not let future information into features. Also fit preprocessing, imputation, feature selection and tuning only on the training portion of each split. Tune on development data; evaluate the final procedure on the untouched test set. If you use the test results to redesign the procedure, you need a new independent evaluation.

Audit a model whose validation score looks too good

A follow-up service predicts a 30-day event at enrolment. In this separate eight-person teaching example, the two candidate pipelines are evaluated on the same held-out people. One uses enrolment measurements. The other also uses a case-closure code entered after day 30 that reveals whether the event occurred. A row can be held out while its features still contain future information.

Person30-day eventEnrolment scoreScore using closure code
100.100.05
210.200.95
300.300.05
400.400.05
510.500.95
600.600.05
710.700.95
810.800.95
Which model would you deploy if all you knew were the reported AUCs? What would you ask before choosing?

The pipeline using the closure code has AUC 1.00. The enrolment-only pipeline has AUC 0.75: it orders 12 of 16 event/non-event pairs correctly. Only the enrolment predictors are available when the service must act. The four misordered pairs reveal uncertainty that the leaked feature concealed.

Rebuild the feature pipeline at the decision time

Check when each field first became available to the person making the decision. A laboratory sample collected yesterday can still leak information if its result was posted tomorrow relative to prediction. Reconstruct the historical record as it appeared at enrolment, including unavailable results. Fit imputation, scaling, feature selection and regularization within each training fold.

In the eight-person example, the Brier score changes from 0.0025 with the closure code to 0.205 with enrolment data alone. Smaller is better. The second estimate answers the operational question. Both are illustrative, and a sample of eight gives very imprecise performance estimates.

event <- c(0, 1, 0, 0, 1, 0, 1, 1)
p <- (1:8) / 10
leaked <- ifelse(event == 1, 0.95, 0.05)
c(enrolment = mean((event-p)^2), leaked = mean((event-leaked)^2))

Choose model complexity without spending the test set

Suppose the team compares a linear effect, a spline with several knots, and a boosted tree with many tuning settings. Selecting the best apparent training fit rewards flexibility. Selecting the best test-set score also uses those outcomes to make a modelling decision. Both choices can exaggerate expected performance.

For a study with adequate numbers, hold out a later cohort before development. Compare the candidate pipelines and tune them within the earlier cohort using resampling that respects the intended prediction unit. Lock the preprocessing and model, refit on the development cohort, then evaluate once on the later cohort.

The best tree wins by a small margin across development folds but performs worse in the later cohort. What would you report?

Report both results, their uncertainty, event counts and the validation design. Examine case mix, feature availability and calibration over time. If you revise the model after inspecting the later cohort, evaluate that revision on fresh data.

Internal validation tests the development process

Training performance is optimistic when the same outcomes influenced variable selection, tuning and fitting. In cross-validation, hold out one fold, repeat the entire fitting pipeline on the remaining folds, and predict the held-out records. Repeat until every record has a held-out prediction. If the same resampling is used to select among many candidates, use nested resampling or an independent evaluation to assess the selected procedure.

For a future deployment, freeze the model before examining the later cohort. Record differences in event frequency, predictor distributions, follow-up completeness and measurement practices. A performance change helps locate a problem; it rarely identifies its cause by itself.

Which numbers answer which questions

Discrimination asks whether higher-risk people tend to rank above lower-risk people. Calibration asks whether predicted probabilities agree with observed risks. For example, compare the predicted and observed rates in risk groups and inspect a calibration curve. The Brier score measures squared probability error. If an action follows a prediction, choose a threshold using the costs and benefits in the intended setting, not just the highest AUC.

Worked calibration check

Use the workshop’s five groups of 20 people. In the original cohort the scores of 10%, 20%, 30%, 40% and 50% predict 30 events in total, and 30 occur. In the later cohort each group has two additional events. The model still predicts 30, while 40 occur. Inspect each group as well as the total: agreement in the aggregate can hide errors in opposite directions across groups. With 20 people per group, one additional event changes the observed group risk by five percentage points.

Discrimination through a pair of people

Take one person who experienced the event and one who did not. Give the model one point if the first person has the higher score, half a point for a tie, and zero if the order is reversed. The average over all such pairs is the empirical AUC.

Suppose two people with events have scores 0.40 and 0.30, and two without events score 0.30 and 0.10. Across four pairs the credits are 1, 1, 0.5 and 1. AUC is 3.5/4 = 0.875. Adding ten percentage points to all four scores preserves every pair and therefore preserves AUC. The predicted number of events still increases.

Calibration and probability error in the later cohort

In five equally sized groups, the original scores are 10%, 20%, 30%, 40% and 50%. The later observed risks are 20%, 30%, 40%, 50% and 60%. On a graph with predicted risk on the horizontal axis and observed risk on the vertical axis, every point lies above the diagonal: the model systematically underpredicts in this example.

The Brier score averages (observed outcome − predicted probability)² over individuals. In the group scored at 40%, ten people have events and ten do not. Its contribution is [10 × (1 − 0.40)² + 10 × (0 − 0.40)²]/20 = 0.26. Across all five groups the score is 0.230. Adding ten points to every prediction lowers it to 0.220. This is an illustrative correction chosen after seeing the outcomes. A fresh cohort is needed to evaluate the updated model.

Turn a threshold into a decision

At a threshold of 40% in the later cohort, the two highest groups qualify. Of 40 people selected, 22 experience the event and 18 do not. Among the 60 remaining people, 18 experience the event and 42 do not. Sensitivity is 22/40 = 55%. Positive predictive value is also 22/40 = 55%, but its denominator is everyone selected. The two percentages happen to agree here.

A lower threshold of 30% captures eight more events but requires 20 more follow-up places. With capacity fixed at 40, that option is infeasible. To establish whether acting on the model improves outcomes, one must also consider the effectiveness, burden and harms of follow-up.

Practice: audit your design

Draw a timeline. Mark the last acceptable feature date and the 30-day outcome window. Specify one baseline model, one test split, a discrimination metric and a calibration check. Then list what could make the test population different from the one that will actually receive predictions.

Write a validation conclusion

In this illustrative later cohort, the original probabilities forecast 30 events and 40 occurred. The highest-scoring 40 people included 22 of the 40 events. The model underpredicted risk across all five score groups. These results justify investigating the drift and evaluating a revised model before using absolute probabilities for planning.

In an actual report, include uncertainty intervals, the number of events, handling of missing outcomes, and results in relevant sites or subgroups where data permit. With repeated observations, account for clustering when estimating uncertainty. State where performance remains unknown and how it will be monitored.

Further reading: Riley and colleagues, Evaluation of clinical prediction models (part 2): how to undertake an external validation study. BMJ 2024;384:e074820. DOI 10.1136/bmj-2023-074820.

Discussion

Questions, clarifications and applications of this resource.

Loading discussion…