Definition
Choose several forecast origins. At each one, fit the model on the observations before the origin and score it on the next h observations. The training window can grow with each origin (expanding window) or keep a fixed length (sliding window). Tashman's review of 2000 calls the procedure rolling-origin evaluation.
for each origin tk: train on y1 ... ytk, test on ytk+1 ... ytk+h
Every score is obtained in the situation the model will face in use: nothing from the future of the origin enters the fit, the tuning or the scaling of the errors.
Worked example
The series is a random walk and the only input is the date. There is nothing to learn: the future steps are independent of everything known. A nearest-neighbour model is scored with shuffled 5-fold cross-validation, then with a walk-forward split.
import numpy as np
from sklearn.model_selection import KFold, TimeSeriesSplit, cross_val_score
from sklearn.neighbors import KNeighborsRegressor
rng = np.random.default_rng(0)
y = np.cumsum(rng.normal(size=600)) # random walk
X = np.arange(600).reshape(-1, 1) # the date, nothing else
model = KNeighborsRegressor(n_neighbors=3)
shuffled = cross_val_score(model, X, y, cv=KFold(5, shuffle=True, random_state=0), scoring="r2")
forward = cross_val_score(model, X, y, cv=TimeSeriesSplit(5), scoring="r2")
print(f"shuffled 5-fold: mean R2 = {shuffled.mean():+.2f}")
print(f"walk-forward: mean R2 = {forward.mean():+.2f} per origin: {np.round(forward, 2)}")Output, produced by running the code above when this page was built:
shuffled 5-fold: mean R2 = +0.99 walk-forward: mean R2 = -1.59 per origin: [-1.18 -0.94 -1.73 -1.21 -2.9 ]
Shuffled folds let the model read the neighbours of each test point, on both sides in time, and report a high score. The walk-forward score is negative: with the past only, the model does worse than predicting the average.
Where it misleads
- The first origins train on little data and the scores are not comparable across origins. Report them per origin as well as on average.
- Only the most recent part of the history is ever tested. A model that fails in a regime found only early in the data is not caught.
- With few origins the estimate is noisy and pessimistic for a model that needs a long history. In our own measurement, walk-forward reported −0.084 for a skill whose true value was +0.073.
- The origins used to choose settings must not be the ones used to report the result. A separate final window, read once, closes that gap.
When labels span several periods, the observations just before an origin overlap the test window and must be removed, as in purged k-fold with an embargo.
In our work
Every forecast we report is scored walk-forward, each origin fitted on its own past. In a controlled experiment, random 5-fold reported an R² of +0.24 on a series with nothing to predict, in 30 runs out of 30.
Service: machine learning and model validation Research note: time series cross-validation, measured
References
- Tashman, L. J. (2000). Out-of-sample tests of forecasting accuracy: an analysis and review. International Journal of Forecasting, 16(4), 437-450. doi:10.1016/S0169-2070(00)00065-0
- Bergmeir, C., Hyndman, R. J., Koo, B. (2018). A note on the validity of cross-validation for evaluating autoregressive time series prediction. Computational Statistics and Data Analysis, 120, 70-83. doi:10.1016/j.csda.2017.11.003
- Hyndman, R. J., Athanasopoulos, G. (2021). Forecasting: principles and practice, 3rd edition. OTexts, Melbourne. otexts.com/fpp3
- scikit-learn developers (2026). Cross-validation: evaluating estimator performance. scikit-learn user guide. scikit-learn.org/stable/modules/cross_validation.html