Back to models
Splitter

SingleWindowSplitter

Single window splitter.

Split time series into a single training and test set window.

The training set is defined based on a “window”. The endpoint of the training set is determined by the length of the time series - fh[-1] - 1, and the starting point is calculated as endpoint - window_length + 1. If the starting point is negative, it will be set to 0.

If the time points in the data are \((t_1, t_2, \ldots, t_N)\), the training windows will be all indices in the interval

\[[t_N-fh[-1] - w, \ldots, t_N-fh[-1] - 1]\]

where \(w\) is the window length and N the length of the time series.

The test window will contain as many indices as there are forecasting horizons provided to the fh argument. In particularly, they will be equal to the endpoint plus the forecasting horizon.

For a forecasting horizon \((h_1,\ldots,h_H)\), the test indices will consist of the indices \((k+h_1,\ldots,k+h_H)\), where k is the end of the training window.

Important Notes:

  • SingleWindowSplitter uses positional indexing (iloc) for the training and

    test windows, regardless of the type of window_length. Even if window_length is a timedelta or pd.DateOffset, the splitter interprets it in terms of the number of positions.

  • window_length can be an integer, timedelta, or pd.DateOffset, where:

    • If int, it specifies the number of time points directly.

    • If timedelta or pd.DateOffset, it represents a relative duration, but it will still be applied as a positional offset, not based on label-based indexing.

Example Calculation: For example, with window_length = 5, fh = [1, 2, 3] and time points \((t_0, t_1, t_2, t_3, t_4, t_5, t_6, t_7, t_8, t_9, t_{10})\), the resulting folds are as follows:

  • [3, 4, 5, 6, 7] = training fold indices.

  • [8, 9, 10] = test fold indices.

Quickstart

python
from sktime.split.singlewindow import SingleWindowSplitter

estimator = SingleWindowSplitter(fh, window_length=None)

Parameters(2)

fhint, list or np.array, optional (default=1)

Forecasting horizon, determines the test window. Should be relative. The test window is determined by applying the forecasting horizon fh to the end of the training window.

window_lengthint or timedelta or pd.DateOffset, optional (default=10)
Window length of the training window.

Examples

>>> import numpy as np
>>> from sktime.split import SingleWindowSplitter
>>> ts = np. arange (10)
>>> splitter = SingleWindowSplitter (fh = [2, 4 ], window_length = 3)
>>> list (splitter. split (ts)) [(array([3, 4, 5]), array([7, 9]))]