The Sliding Window For Sequences
Sequence models such as recurrent networks need many input and target pairs. A sliding window generates these pairs from one long series.
How the window slides
- Pick an input length, the number of past steps the model sees.
- Pick a horizon, the number of future steps to predict.
- Take a window of inputs, record the following steps as the target, then slide forward by one step and repeat.
This produces many overlapping samples, each a small forecasting problem drawn from the same series.
Tuning the cut
- A longer input window gives more context but fewer samples and slower training.
- A longer horizon is harder because errors compound across steps.
- The slide step controls overlap. A step of one maximizes samples, while a larger step reduces redundancy.
A caution
When you split into train and test sets, respect time order. A window must never include points from after the test boundary, or the model effectively sees the future.
Key idea
A sliding window slices one series into many overlapping input and target pairs, feeding sequence models while respecting time order.