Walk-forward validation: testing a model in chronological order
On this page
Has the reported accuracy of your forecasts been measured over time?
Let's plan an exchangeDiscover our sales forecasting softwareTemporal validation, or walk-forward validation, tests a model by adhering to chronological order: it is trained on one timeperiod and evaluated on the next—never the other way around. It replaces traditional cross-validation, which mixes past and future data. This is what distinguishes reported accuracy from actual accuracy in production.
The Essentials
- Temporal validation always evaluates the model over a period that comes after the training period.
- Traditional cross-validation using random sampling produces results that are too favorable when it comes to sales.
- The time frame for the test must be the same as that for the actual decision, including the lead time.
In 6 Questions
A test that progresses over time.
Data scientists, forecasters, and buyers of forecasting solutions.
Each time a model is evaluated on historical data.
Sales forecasting, elasticity, promotion simulation.
Achieve a precise measurement that holds up over time.
Train on the past, test on what follows, then repeat.
Traditional validation or time-based validation?
The difference lies in how the data is divided between training and testing.
| Criterion | Traditional Cross-Validation (K-Fold) | Time Validation |
|---|---|---|
| Cutting | Randomly Selected Blocks | Successive periods |
| Order of Time | Not complied with | Respected |
| Based on sales | Results that are too flattering | Results Close to Actual Service Performance |
| Suitable for | Data without a time dimension | Any dated data |
Mixing the past and the future in a time series is equivalent to giving the model part of the answer. This constitutes a data leak.
How does a time-based validation work?
The process is repeated exactly the same way, shifting the cutoff date each time.
- Step 1: The model learns from historical data up to a given date.
- Step 2: It forecasts the next period, based on the actual time horizon.
- Step 3: Compare your forecasts with actual sales.
- Step 4: Move up the cutoff date and start over.
There are two variants. With an expanding window, the training period gets longer with each step. With a rolling window, it maintains a fixed duration and discards the oldest data.
The whole thing constitutes a backtest: temporal validation serves as the criterion for segmenting the data.
Why It Matters in Pricing
A price recommendation affects volume and margin. It relies on accuracy that must be trustworthy.
A machine learning model evaluated using random sampling will initially show a low error rate, but will then fall short within the first few weeks. The discrepancy results in stockouts, excess inventory, and a loss of confidence among teams.
The question to ask a vendor is simple: Has the claimed accuracy been measured over the time frame relevant to my decision-making? This is one of the factors to consider when choosing sales forecasting software.
The Limits of Temporal Validation
The method is sound. It comes at a cost and has a few blind spots.
- It consumes historical data: each test period is removed from the training set, which can be a problem when the dataset is small.
- It requires computation: the model is retrained at each step.
- It assumes a representative history: after a data gap, historical periods provide unreliable information.
- She only notes what has happened: she says nothing about a price that has never been charged.
Our belief: accuracy measured outside the context of time is worthless. We explain this principle in detail in our article on AI-powered sales forecasting in retail, and we apply it to our AI-powered sales forecasting.
See also in the glossary:lags · MSE and RMSE · ARIMA and exponential smoothing · CRPS
Frequently Asked Questions
Short answers to the most frequently asked questions about time-based validation.
What is time-based validation?
Temporal validation is a method for testing a model that respects the order of time. The model is trained over one time period and then evaluated over the following time period—never over a previous one. This process is repeated as the timeline progresses, hence its name, “walk-forward validation.” It applies to all dated data, such as sales or prices. It replicates the real-world situation, where we always predict the future based on the past.
Why isn't traditional cross-validation suitable for sales?
Traditional cross-validation, known as K-fold cross-validation, randomly divides the data into several blocks and then tests the model on each block after training it on the others. With sales data, this random division places future weeks in the training set and past weeks in the test set. The model therefore already knows the trend and the season it is supposed to predict. Its results appear excellent but do not hold up in production. This is a form of data leakage.
What is the difference between backtesting and time-based validation?
The two concepts largely overlap. Backtesting refers to the process of simulating past data to see what the model would have predicted. Walk-forward validation refers to the rule that ensures this process is fair: always test on a period that comes after the training phase. A rigorous backtest therefore relies on temporal validation. In practice, business teams refer to it as a backtest, while data scientists refer to it as temporal validation or walk-forward.
Should you use a rolling window or an expanding window?
With a expanding window, training always starts from the beginning of the history and extends further with each step: the model has access to more and more data. With a rolling window, it retains only a fixed time period—for example, the last two years—and discards the oldest data. The first approach is suitable when sales patterns are stable. The second is suitable when the market has changed and older data no longer reflects the current situation.
How many test periods are needed?
Enough to cover a variety of situations. A single test period may be exceptionally easy or difficult and lead to a false conclusion. Multiple periods, spread out over the year, allow you to observe the model during peak season, off-season, and during major sales events. The number depends on the depth of the historical data: with three years of data, you can test the model over about ten periods while still retaining enough data for training.
What is the gap between training and testing?
This is a deliberate time lag between the end of the training period and the start of the testing period. It replicates the time that, in reality, elapses between the calculation of the forecast and the moment it is used. If an order must be placed four weeks in advance, testing the model on the following week overestimates its performance: it must be evaluated over a four-week period. Overlooking this gap is a common cause of disappointment after implementation.
Does time-based validation apply to the calculation of price elasticity?
Yes. Elasticity is estimated based on historical price and sales data and is used to predict the response to a future price. The proper way to test it is to estimate it over a given period and then verify whether it would have accurately predicted the effect of subsequent price changes. An elasticity estimated using the very data used to calculate it always appears reliable. Only testing it against a subsequent period reveals whether it holds up.
Key Takeaways
- Time-based validation always tests over a period following the training session.
- Random sampling of sales yields results that are too optimistic.
- The scope of the test must be that of the actual decision.
Are you looking for a precise measurement that holds up under real-world conditions?
Booper evaluates its forecasts chronologically, based on your historical data and in light of your upcoming decisions.
Let's talk about the reliability of your forecasts →Discover our sales forecasting softwareThese articles can interest you
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.
When comparing sales forecasting solutions, there are five key points to check before conducting any tests: demand hidden by stockouts, the forecast granularity, an explanation of each figure, the relationship with prices and promotions, and an honest assessment of accuracy.
A demonstration doesn't prove anything on these points. Only a test using your own data, compared to a simple baseline, will show whether the forecast truly improves your decisions.
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.