Skip to main content

What is data leakage in machine learning?

The Harvard Chan AI Glossary

In our classes, we often pause to explain the ideas behind AI and the language used to describe it. These posts grew out of those conversations. They’re for anyone who would like to understand AI better, with no technical background assumed.

Data leakage occurs when information enters model development or testing in a way that would not be available in the intended prediction situation. It can make performance look misleadingly good. The model appears to solve a task while benefiting from clues it would not possess when the prediction actually needs to be made.

Suppose a retailer wants to predict whether an order will be returned at the time it is placed. A record showing that a refund was issued later is not a legitimate input for that prediction. It reveals information from the future. The model may learn a strong pattern, but it is answering a different and much easier question.

A feature is an individual piece of information supplied to a prediction model. A label is the reference answer used to teach or evaluate it. Leakage can occur when a feature directly or indirectly reveals the label. It can also occur when information from examples reserved for testing influences the development process.

A test set is a collection of examples kept separate to examine how the model handles cases beyond those used for learning. If the team repeatedly adjusts its method to perform well on those exact examples, the result becomes less informative about genuinely new cases. The apparent independence of the test has been weakened.

Related records need care too. If nearly identical versions of the same item appear in both learning and test collections, the model may benefit from familiarity. The right separation depends on the intended use: predicting for new customers, future dates and new organizations are different questions.

Start with the timing question: what would the system actually know when it has to answer? Exclude measurements that would only become available afterward.

This technical meaning of leakage differs from a privacy leak, where confidential information is exposed to an unauthorized recipient. Both matter, but they are not the same problem. A model can suffer from data leakage even when nobody outside the organization sees the data.

In the course’s patient-data demonstration, later measurements were excluded because they would not have been known when the patient arrived. The same principle applies to the psychiatric pathway proposal: a prediction made at initial assessment cannot use a later disposition note or subsequent outcome. A variable can look clinically sensible while still coming from the future. Define the prediction time first, then check when every input became available. Otherwise, an impressive score may describe access to the answer rather than a useful prediction.

Source: scikit-learn — Common Pitfalls and Recommended Practices.

If you would like to find out more about AI and improve your leadership skills, consider the AI in Health Care Certificate of Specialization from the Advanced Learning Academy at Harvard T.H. Chan School of Public Health. You can take an individual course or work toward the full certificate.


AI is a fast-moving field. This explanation reflects our class discussions and related material at the time of writing. Terminology, capabilities and tools may change.

For suggested additions or corrections, please email me at tpanch@hsph.harvard.edu.

Dr. Trishan Panch
Program Director, AI in Health Care
Harvard T.H. Chan School of Public Health — Advanced Learning Academy