SlidingWindowSplitter#
- class SlidingWindowSplitter(fh: Union[int, list, numpy.ndarray, pandas.core.indexes.base.Index, sktime.forecasting.base._fh.ForecastingHorizon] = 1, window_length: Union[int, float, pandas._libs.tslibs.timedeltas.Timedelta, datetime.timedelta, numpy.timedelta64, pandas._libs.tslibs.offsets.DateOffset] = 10, step_length: Union[int, pandas._libs.tslibs.timedeltas.Timedelta, datetime.timedelta, numpy.timedelta64, pandas._libs.tslibs.offsets.DateOffset] = 1, initial_window: Optional[Union[int, float, pandas._libs.tslibs.timedeltas.Timedelta, datetime.timedelta, numpy.timedelta64, pandas._libs.tslibs.offsets.DateOffset]] = None, start_with_window: bool = True)[source]#
Sliding window splitter.
Split time series repeatedly into a fixed-length training and test set.
For example for window_length = 5, step_length = 1 and fh = 3 here is a representation of the folds:
|-----------------------| | * * * * * x x x - - - | | - * * * * * x x x - - | | - - * * * * * x x x - | | - - - * * * * * x x x |
*= training fold.x= test fold.- Parameters
- fhint, list or np.array
Forecasting horizon
- window_lengthint or timedelta or pd.DateOffset
Window length
- step_lengthint or timedelta or pd.DateOffset, optional (default=1)
Step length between windows
- initial_windowint or timedelta or pd.DateOffset, optional (default=None)
Window length of first window
- start_with_windowbool, optional (default=False)
If True, starts with full window.
If False, starts with empty window.
Methods
get_cutoffs([y])Return the cutoff points in .iloc[] context.
get_fh()Return the forecasting horizon.
get_n_splits([y])Return the number of splits.
split(y)Split y into training and test windows.
- get_cutoffs(y: Optional[Union[pandas.core.series.Series, pandas.core.frame.DataFrame, numpy.ndarray, pandas.core.indexes.base.Index]] = None) numpy.ndarray[source]#
Return the cutoff points in .iloc[] context.
- Parameters
- ypd.Series or pd.Index, optional (default=None)
Time series to split
- Returns
- cutoffs1D np.ndarray of int
iloc location indices, in reference to y, of cutoff indices
- get_fh() sktime.forecasting.base._fh.ForecastingHorizon[source]#
Return the forecasting horizon.
- Returns
- fhForecastingHorizon
The forecasting horizon
- get_n_splits(y: Optional[Union[pandas.core.series.Series, pandas.core.frame.DataFrame, numpy.ndarray, pandas.core.indexes.base.Index]] = None) int[source]#
Return the number of splits.
- Parameters
- ypd.Series or pd.Index, optional (default=None)
Time series to split
- Returns
- n_splitsint
The number of splits.
- split(y: Union[pandas.core.series.Series, pandas.core.frame.DataFrame, numpy.ndarray, pandas.core.indexes.base.Index]) Generator[Tuple[numpy.ndarray, numpy.ndarray], None, None][source]#
Split y into training and test windows.
- Parameters
- ypd.Series or pd.Index
Time series to split
- Yields
- trainnp.ndarray
Training window indices
- testnp.ndarray
Test window indices