Retour à la bibliothèque
Guide · Prédiction · 15 sections

Prédiction et validation des modèles

Préciser l’objectif de prédiction et évaluer le modèle sur des observations tenues à l’écart de l’entraînement.

La lecture en ligne ne nécessite pas de compte.

Déploieriez-vous ce modèle de risque ?

Une équipe peut assurer le suivi de 40 personnes sur 100. Un modèle estime le risque à 30 jours à partir des données disponibles à l’inclusion. Validez ses prédictions dans deux cohortes fictives de 100 personnes, avec 20 personnes par score.

Essayez d’abord un seuil de 30 % et comptez les personnes admissibles. Relevez-le ensuite d’un palier. Une fois les 40 places occupées, comparez les événements prévus et observés dans chaque cohorte.

Voir la réponse et son interprétation

Au seuil de 40 %, les deux groupes aux scores les plus élevés sont admissibles, soit 20 personnes par groupe. Le modèle y prévoit 8 + 10 = 18 événements. Dans la cohorte initiale, on observe 18 événements. Passez à la cohorte ultérieure pour vérifier si la prévision tient toujours.

Calibration par groupe de risque

0%0%20%20%40%40%60%60%Risque observéRisque prédit
Chaque point représente 20 personnes. Les pointillés indiquent une concordance parfaite.
PréditObservéÉvén. / N
10%10%2 / 20
20%20%4 / 20
30%30%6 / 20
40%40%8 / 20
50%50%10 / 20

Choisir un seuil de suivi

Choisissez le seuil proposé le plus bas qui respecte la capacité de suivi. Toute personne dont le score atteint ou dépasse ce seuil sera suivie.

Personnes à suivre60 / 100
Événements repérés24 / 30
Événements manqués6
Sensibilité80%
Valeur prédictive positive40%
Interpréter cette validation

Dans cette cohorte fictive, les proportions observées correspondent aux scores. Passez à la cohorte ultérieure pour voir si les mêmes scores correspondent toujours aux mêmes risques absolus.

Peut-on améliorer les probabilités sans changer le classement ?

Gardez les mêmes 100 personnes et leurs résultats. Comparez les scores initiaux à une version qui ajoute 10 points de pourcentage à chaque prédiction. Avant de changer, dites si le nombre prévu d’événements, le classement ou les deux vont changer.

Comparaison des scores dans la cohorte choisie
Événements prévus / observés30 / 30
Discrimination (AUC)0,690
Erreur quadratique moyenne des probabilités (score de Brier)0,190

Lire le chapitre 13 sur la validation (en anglais) · Lire le chapitre 14 sur le risque et l’équité (en anglais)

Voir la réponse et son interprétation

Ajouter la même valeur à chaque score préserve le classement de toutes les paires. L’AUC reste donc fixe dans cette cohorte. Elle compare une personne ayant eu un événement à une autre sans événement et accorde un demi-point en cas d’égalité. Le score de Brier mesure l’erreur des probabilités par rapport aux résultats individuels. Plus il est faible, plus les probabilités sont précises.

Ici, les scores initiaux correspondent déjà aux risques observés des cinq groupes. Ajouter 10 points fait passer la prévision de 30 à 40 événements alors qu’on en observe 30. Reprenez la comparaison dans la cohorte ultérieure.

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, précisions et applications de cette ressource.

Chargement des commentaires…