Data Leakage: When a Model Unwittingly Cheats
On this page
Do your forecasts deliver in real-world use what they promised during testing?
Let's plan an exchangeDiscover our sales forecasting softwareIn machine learning, data leakage occurs when a model is trained using information that it will not have access to when making predictions. The test results are excellent, but the reality is disappointing. The term does not have the same meaning as it does in computer security. In pricing, a typical example is the actual price paid, which is known only after the sale.
The Essentials
- A data leak occurs when information about the future—or information that is unknown under real-world conditions—is used to train a model.
- It produces promising test results but disappointing outcomes once the model is in use.
- It is prevented by checking, for each variable, at what point its value is actually known.
In 6 Questions
Information that is not actually available, but is used in training.
Data scientists, pricing managers, and buyers of AI solutions.
When creating variables and during testing.
In prices, inventory, averages, and the testing method.
Avoid a model that performs well in testing but disappoints in actual use.
By following the chronological order at each stage.
Types of Data Leakage
Data leaks are almost never intentional. They creep into the data preparation process or the way tests are conducted.
| Form | What's Going On | Example in retail |
|---|---|---|
| Time Leak | The Past and Future Mix Test | The model uses data from March to predict January |
| Variable Known in Hindsight | Data only exists once the sale is complete | Price paid, including discounts; end-of-day inventory |
| Contaminated aggregate | An average includes the period to be forecast | Average annual sales, including future weeks |
| Duplicates | The same observation appears in both training and testing | A product listed under two codes |
The first three forms relate to the order of time. They apply to any data organized into a time series.
Why Data Leakage Matters in Pricing
Price is the most exposed variable, because it comes in many forms.
The listed price is set in advance. The actual price paid depends on checkout discounts, loyalty benefits, and promotional offers. It is not recalculated until after the sale.
A model trained on the price paid, and then fed the listed price during operation, no longer receives the same information. Its recommendations are based on a relationship that does not exist under real-world conditions.
The choice of explanatory variables is therefore also a matter of timing: knowing which data are available and when.
We discuss these checks in detail in the article on the sales history data needed for reliable forecasting.
Warning Signs to Watch For
A data leak doesn't cause an error. It produces results that are too good.
- Unusual performance: accuracy far exceeding what is typically seen in retail sales.
- A dominant variable: a single factor explains almost everything—far more than price or promotions.
- A performance gap: results begin to decline as early as the first few weeks of actual use.
The third signal arrives too late. That's why it's important to conduct a backtest that accurately replicates production conditions before deployment.
How can you protect yourself from it?
Prevention hinges on a few methodological rules—simple to state but difficult to follow.
- Testing as time progresses: Each test period occurs after the corresponding training period.
- Label each variable: note when its value is known and in what form.
- Calculate running averages: using only data prior to the forecast date.
- Involve the business: Teams know which information comes before or after the decision.
Our belief: If a result seems too good to be true, verify it before celebrating. Data quality determines the limits of what a model can achieve, as explained in our article on data quality in pricing.
Our AI-powered sales forecast is tested under real-world conditions, using only the data available at the time a decision is made.
The safest safeguard is still temporal validation, which prevents the model from seeing the future.
See also in the glossary:lagged variables · unconstrained demand · forecast bias · global model
Frequently Asked Questions
Short answers to the most frequently asked questions about data leakage.
What is data leakage in machine learning?
Data leakage occurs when a model learns from information that it will not have available when making an actual prediction. During testing, the model appears to perform very well because it essentially has part of the answer. Once in production, this information is missing, and performance deteriorates. This is one of the most common causes of the discrepancy between a model’s advertised performance and its actual performance in the real world.
How is this different from a data breach in the context of security?
The two terms have nothing to do with each other. In IT security, a data leak refers to the disclosure of confidential information—for example, customer data exposed to third parties. In machine learning, a data leak is a methodological flaw: information about the future—or information that is unknown under real-world conditions—has crept into a model’s training data. Nothing leaves the company. To avoid confusion, data scientists often use the English term “data leakage.”
What are some examples of data leaks related to sales forecasting?
The most common approach is to use the actual price paid—including discounts—to train the model, even though only the projected price is known in advance. Another option is the end-of-day inventory, which depends on the sales being forecasted, or an average of sales calculated over the entire year, including the weeks to be forecasted. Another common scenario involves a test that randomly shuffles the weeks, so that the model learns from March data to forecast January.
How can you detect data leakage?
There are three warning signs to watch for: test results that are significantly better than what is typically observed for this type of problem; a variable that overwhelmingly dominates all others in the model’s explanation; and a marked discrepancy between performance measured in testing and performance observed after implementation. In all three cases, it is necessary to review each variable and verify at what point its value is actually known in the decision-making process.
How can you prevent data leaks?
By adhering to the timeline at each stage. The test must always cover a period after the training period. Each variable must be calculated using only the data available as of the forecast date, including averages and cumulative totals. Within the systems, a distinction must be made between the forecast value and the observed value for the same piece of information. Finally, involving the business teams is very helpful: they know which data arrives when.
Why does traditional cross-validation pose a problem for sales?
Traditional cross-validation divides the data into randomly selected blocks, then trains the model on some of the blocks and tests it on the others. For data without a time dimension, this method works well. For sales data, however, it mixes past and future data: the model may learn from weeks that come after those it is supposed to forecast. It therefore already knows the trend and the season. A forward-looking validation method is preferred, in which each test occurs after the training phase.
Does the data leak also affect the calculation of price elasticity?
Yes. Elasticity is calculated by relating prices to sales, and the same caution applies. If the price used is an observed average price, it includes discounts granted in response to sales, which obscures the nature of the relationship. If sales figures include unreported periods of stockouts, the price response is overestimated. In both cases, the resulting coefficient appears accurate but leads to poor recommendations when applied.
Key Takeaways
- Data leakage causes the model to learn information that is not available under real-world conditions.
- In pricing, the actual price paid and outdated averages are common sources of data.
- It is prevented by following the chronological order and dating each variable.
Would you like to verify that your forecasts will hold up under real-world conditions?
Booper tests its forecasts using only the data available at the time of the decision, based on your historical data.
Let's talk about the reliability of your forecasts →Discover our sales forecasting softwareThese articles can interest you
How much historical data is needed for forecasting? It depends on the category, but reliability matters more than depth: historical data in which breaks, promotions, and price changes are dated is better than a long, unprocessed data set.
Two factors are often overlooked: the history of prices paid—without which elasticity cannot be measured—and the years of inflation, as reflected in volume figures. The adjustment begins with the items that account for the bulk of sales.
AI is only as good as the data it’s fed, and a more powerful model trained on poor-quality data produces more convincing errors. Obvious errors are easy to spot; it’s the plausible errors—such as a purchase cost that’s off by a few percent—that erode the margin.
Waiting for perfect data is another way to fail. A broken data model is fixed before configuration; the rest is made reliable through use, starting with the data points that drive sales, with a manager assigned to each type of data.
AI-based sales forecasting estimates demand for each product, store by store, by separating baseline demand from promotional demand. AI takes in more data points than a spreadsheet, but its value lies solely in the decisions it helps inform.
In retail, this decision is primarily about pricing or a promotion. A useful pricing forecast—one that estimates how much will be sold at each considered price—is evaluated based on its bias rather than its MAPE, and is validated against control stores.