Time series cross-validation

Also known as: rolling-origin evaluation · walk-forward validation

On this page 7

Time series cross-validation is a model evaluation procedure that trains only on past observations and tests on the periods that follow, repeating this split at several points in time to estimate how well a forecasting model will perform on genuinely unseen future data. Within time series & forecasting, a core area of artificial intelligence and machine learning, it is also known as rolling-origin evaluation or walk-forward validation.

Ordinary k-fold cross-validation shuffles data into random folds, which lets a model see the future while predicting the past. Because consecutive observations are correlated, that shortcut produces optimistic error estimates and can select models that fail in production. Time series cross-validation respects the arrow of time, so the measured error reflects the conditions under which the model will actually be used.

How rolling-origin evaluation works

Rolling-origin evaluation works by moving a forecast origin forward through the series. At each origin, the model is fitted on all data up to that point, it produces forecasts for the chosen forecast horizon, and those forecasts are compared with the observed values; the errors from all origins are then averaged.

The procedure has a small number of design parameters. The table below lists them and explains what each one controls.

ParameterWhat it controlsTypical choice
Initial training windowData available to the first fitAt least two full seasonal cycles
Forecast horizonHow far ahead each test reachesMatches the business horizon
Step sizeDistance between successive originsOne period up to one horizon
Number of foldsHow many origins are evaluated5 to 50, limited by compute
GapPeriods skipped between train and testEqual to data latency or lag length
Refit frequencyWhether the model is retrained per foldEvery fold, or every few folds
Design parameters of time series cross-validation

The gap parameter is often overlooked. When features use lagged or rolling values, or when data arrives with a reporting delay, the gap prevents information from the test period from leaking into the last training rows.

Expanding, sliding and blocked schemes

Time series cross-validation comes in several split schemes that differ in how the training window behaves as the origin moves. The right scheme depends on whether old data remains relevant and on how much the process changes over time.

The following table compares the common schemes.

SchemeTraining windowBest suited toMain drawback
Expanding windowGrows from a fixed startStable processes, short historiesOld regimes may dominate
Sliding windowFixed length, moves forwardDrifting or changing processesDiscards useful history
Blocked cross-validationContiguous blocks with buffersStationary series, small datasetsTrains on some future data
Single holdoutOne split at the endQuick checks, very long seriesHigh variance, one period only
Purged and embargoed splitsRemoves overlapping labelsFinancial labels spanning timeSmaller effective sample
Common split schemes

An expanding window is the usual default for classical models such as ARIMA and the ETS model. A sliding window is preferred when the data shows structural breaks, because it measures how the model performs with only recent, representative history.

Choosing metrics and aggregating fold errors

Fold errors must be measured with scale-appropriate metrics and aggregated with care. MASE is often preferred over MAPE because it remains defined when actual values are zero and it compares the model with a naive forecast on the same series.

Errors should also be reported per horizon step, since a model may be excellent one day ahead and weak a week ahead. For probabilistic forecasting, the same splits are scored with pinball loss or interval coverage rather than point accuracy.

The table below shows how evaluation choices change with the forecasting setting.

SettingRecommended metricAggregation approach
Single series, positive valuesMAPE or MASEMean over folds and horizons
Many series with different scalesMASE or scaled RMSEAverage of scaled errors
Intermittent demandMASE or cost-based lossTotal over folds
Quantile forecastsPinball lossMean per quantile level
Hierarchical forecastsScaled error per levelWeighted by business value
Evaluation choices by forecasting setting

Using cross-validation for model selection

The main practical use of time series cross-validation is choosing between models and hyperparameters under realistic conditions. Libraries such as scikit-learn’s TimeSeriesSplit, sktime and GluonTS provide ready-made splitters, while statistical packages offer rolling-origin functions for classical models.

A disciplined workflow keeps a final untouched test period at the end of the series. Cross-validation folds are used to tune and compare candidates, and the final period gives a single unbiased estimate for the chosen model, in the same way as a standard train-test split.

  • Fit all preprocessing inside each fold, including scaling, imputation and feature selection.
  • Compute lag features and rolling window features only from data available at the forecast origin.
  • Compare every candidate against a seasonal naive benchmark on identical folds.
  • Report the spread of fold errors, not only the mean, to reveal unstable models.

Pitfalls and sources of leakage

Most failures of time series cross-validation come from subtle look-ahead leakage rather than from the split scheme itself. A model can pass validation and still fail once deployed if any fold used information that would not exist at forecast time.

MistakeSymptomFix
Shuffled k-fold splitsValidation error far below live errorUse ordered, forward-only splits
Global normalizationSlightly optimistic scoresFit scalers inside each fold
Revised data used as finalLive accuracy drops after launchUse point-in-time data vintages
Too few foldsRankings change between runsAdd origins or vary step size
Missing gapLag features leak target valuesInsert a gap equal to the lag
Common mistakes and their fixes

Compute cost is the other limitation. Deep forecasters such as N-BEATS or the Temporal Fusion Transformer can be expensive to refit at every origin, so teams often refit less frequently or reuse weights, accepting a small loss of realism.

Understanding it simply

A forecast is only useful if it works on days that have not happened yet. Time series cross-validation tests a model the same way. It hides the future, lets the model learn from the past, and then checks its guesses.

Then it moves forward in time and repeats the test. Imagine grading a weather forecaster each morning on tomorrow’s weather, for a whole season. One lucky day proves little. Many days in a row show the true skill. The key takeaway is that a model must never peek at the future during testing.

Applied in practice

A regional grocery chain forecasts daily demand for 3,000 products fourteen days ahead to plan orders. Its data science team holds three years of sales history and compares a seasonal naive benchmark, an ETS model and a gradient-boosted global model with lag and calendar features.

The team sets an expanding window with weekly origins over the final year, a fourteen-day horizon and a two-day gap for delayed sales reporting, giving 52 folds. A random k-fold test had suggested the boosted model was 30 percent better than ETS. Under walk-forward validation the advantage shrinks to about 8 percent in MASE, and it holds across most folds. The chain deploys the boosted model with realistic accuracy expectations and a documented benchmark for later monitoring.