SingleWindowSplitter
SingleWindowSplitter
- class SingleWindowSplitter(fh, window_length=None)[source]
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
fhargument. 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:
SingleWindowSplitteruses positional indexing (iloc) for the training andtest windows, regardless of the type of
window_length. Even ifwindow_lengthis a timedelta or pd.DateOffset, the splitter interprets it in terms of the number of positions.
window_lengthcan 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.
- Parameters:
- 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
fhto 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]))]
Methods
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
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.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get a dict of parameters values for this object.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params([parameter_set])Return testing parameter settings for the splitter.
is_composite()Check if the object is composed of other BaseObjects.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
set_config(**config_dict)Set config flags to given values.
set_params(**params)Set the parameters of this object.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.
split(y)Get iloc references to train/test splits of y.
split_loc(y)Get loc references to train/test splits of y.
split_series(y)Split y into training and test windows.

