Modules / Time Series / Sliding Window

Sliding Window for Timeseries Data

Visualize how time series data is processed into windows for forecasting and analysis.

Generated Windows

0 ITEMS

Enter data to generate windows

Tip: Use the bottom slider to scroll quickly through large lists of windows.

Overview

For a one-step forecast, a window of width (W=3) over values 10, 11, 12, 13 creates the input [10, 11, 12] and target 13. Sliding one step gives the next input [11, 12, 13] and its following target. The window is the model’s lookback; the target’s distance from its end is the forecast horizon.

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.

Sources and next steps

Predict, then reveal

About to run: set VIEW to its maximum (100). Before it does — what happens to the readout?

Committing to an answer first is the point — the reveal runs the experiment on the visualisation above and reads the real value back, so nothing here is scripted.

Recall check

0 of 3

Say the answer out loud before you reveal it — recalling it is what makes it stick, and rereading it is not.

  1. What does this module say about “Make examples from a sequence”?

  2. What does this module say about “Choose lookback, stride, and horizon”?

  3. What does this module say about “Split by forecast time”?

Cheat sheet

Sliding Window for Time Series

Slide a window across a time series to turn a raw sequence into supervised training rows of features and targets.

MACHINE LEARNING · vizlearn.in/machine_learning/sliding_window_for_timeseries_data.html

About the author

Ashish Jangra builds and maintains VizLearn. Every module here is written and the visualisation behind it hand-built, so the numbers in a readout come from the same code that draws the picture. Corrections are genuinely welcome and get priority over everything else — if a page states something wrong, or an animation misrepresents what the algorithm does, get in touch.