Make examples from a sequence
Use Window Size (W) and Stride (S) in the visualizer, then scroll along the series to see which observations form each example. A stride of 1 creates the most overlapping windows. A larger stride creates fewer examples and skips some possible starting positions.
Choose lookback, stride, and horizon
A lookback should cover patterns that matter. For daily data with a weekly cycle, a window shorter than seven days cannot include a full week, though longer history is not automatically better. Longer windows increase input size and may include irrelevant older values. Use domain knowledge and validation to compare choices.
Stride determines sampling density, not how far ahead the model predicts. Horizon is a separate choice: a one-step forecast predicts the next observation; a multi-step forecast predicts several future values. Evaluate the horizon you will actually deploy. Recursive forecasts feed predictions back as inputs and can accumulate error; direct or multi-output approaches train for future steps differently.
Split by forecast time
Do not randomly split overlapping windows for a future-forecast task. Nearby windows share many observations, and random splitting can put later targets in training while earlier times are in test. Instead, split by forecast origin: training targets must occur before the validation or test period, matching the information available when each prediction would have been made.
Past observations may legitimately appear in both a training window and the input context for a later test forecast if those observations would be known at deployment. Add a gap when target horizons or label construction cause training targets to overlap the evaluation period; set it based on the horizon and data process rather than automatically using the full window size.
Fit scalers, imputers, and feature selection using the training period only. In rolling-origin evaluation, advance the cutoff and repeat so the model is tested at several future points.
Common mistakes with Sliding Window for Time Series
- Shuffling windows before splitting: creates leakage between nearby examples and can train on the future.
- Confusing stride with horizon: one controls window starts, the other the forecast distance.
- Using a window too short for a known cycle: important periodic history is unavailable to the model.
- Reporting one-step accuracy for a multi-step task: test the actual forecast horizon.