Walk-forward (rolling) CV preserves temporal ordering: you train on past data and validate on future unseen windows to avoid leakage. Standard k-fold shuffles or creates folds that mix future information into training (e.g., using Y_t+1 to predict Y_t), producing optimistic bias because time dependency and autocorrelation violate i.i.d. assumptions.How walk-forward works (high-level):- Choose an initial training window T0, a validation horizon h, and number of steps S.- For step i in 0..S-1: train on data up to time t_i (T0 + i * step), validate on (t_i+1 .. t_i+h). Advance window and repeat.- Collect metrics across validation steps for robust estimate.Practical Python pattern:python
# rolling validation pseudocode
for start in range(initial_train_end, max_time - horizon + 1, step):
train = data[:start]
val = data[start:start+horizon]
model.fit(train_X, train_y)
preds = model.predict(val_X)
evals.append(metric(val_y, preds))
Expanding vs sliding windows:- Expanding: include all past data each step. Good when more history improves learning (stable regime), or when model benefits from long-term patterns.- Sliding (fixed-length): use a fixed recent window that "forgets" old data. Better when data distribution drifts or older data becomes irrelevant.Choose based on stationarity: check concept drift tests, domain knowledge (seasonality length), and validation performance.Choosing window sizes:- Validation horizon h should match business forecast horizon.- Training window length should cover at least several seasonal cycles (e.g., 2–3 years for yearly seasonality).- Step size can be 1 period or larger to reduce compute; ensure sufficient folds for variance estimation.- Account for serial correlation: use block-level splits (no overlap between validation and training within a buffer) to avoid leakage—introduce a gap equal to model lag/seasonal embed length.Regularization & overfitting controls for time series:- Temporal smoothness penalties: penalize rapid changes in predictions or model parameters over adjacent time steps (e.g., add L2 on finite differences of predicted series or on RNN hidden-state transitions).- Weight decay (L2), dropout (for NN), and early stopping evaluated on rolling validation.- Ensembling across windows: average models trained on different rolling folds or use stacked blending—reduces variance and captures different regime behaviors.- Feature/target leakage checks: avoid using future-looking engineered features; when using lag features include only past lags.- Calibration of residuals: use prediction intervals aggregated across folds to estimate uncertainty.- Data augmentation/time warping sparingly: preserve temporal order.Trade-offs:- Expanding window reduces variance but may underweight recent drift. Sliding window adapts to drift but increases variance and needs more data per fold.- More folds → better estimate but higher compute; use nested search or Bayesian optimization with fewer outer folds.Summary: use walk-forward CV with appropriate gap/lag handling, select training/validation lengths by seasonality and horizon, choose expanding vs sliding based on stationarity, and combine temporal smoothness penalties, classical regularizers, and ensembling across windows to prevent overfitting and produce reliable, deployable forecasts.