Detecting label leakage in a predictive pipeline

← Back to Blog & Articles

Retrospective EHR extracts contain billing and diagnosis codes assigned after the stay, and they often encode the outcome one wants to predict.

Retrospective EHR extracts contain billing and diagnosis codes assigned after the stay, and they often encode the outcome one wants to predict. A model that uses them is accurate on historical data and useless at the bedside, where those codes do not yet exist. We simulate this with a code-count feature whose rate rises when an event was observed within 24 months, and which has only a background rate at deployment time.

The coefficient on the code count is 1.857, against a largest tabular coefficient of 0.237. On the retrospective test set the leaky model looks excellent: Harrell C 0.8572 and IPCW Brier 0.1047. At deployment time the same model has C 0.6090 and IPCW Brier 0.1678, worse than the null model’s 0.1566 from the companion book example, and it predicts a mean risk of 0.0724 against a true 0.1972. The model without codes has C 0.6909 and Brier 0.1386 in the same setting. No amount of held-out validation on the retrospective data would reveal the problem, because the leak is present in every split. The defence is procedural: define the prediction time of each feature, include only information with a timestamp before it, and review every feature with a clinician who knows when it is recorded.

Continue with the book

Explore the full treatment, worked examples, and exercises in Applied AI Under Uncertainty.


Companion article for Applied AI Under Uncertainty, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top