make_reduction#
- make_reduction(estimator, strategy='recursive', window_length=10, scitype='infer', transformers=None, pooling='local', windows_identical=True)[source]#
Make forecaster based on reduction to tabular or time-series regression.
During fitting, a sliding-window approach is used to first transform the time series into tabular or panel data, which is then used to fit a tabular or time-series regression estimator. During prediction, the last available data is used as input to the fitted regression estimator to generate forecasts.
Please see below a graphical representation of the make_reduction logic using the following symbols:
y
= forecast target.x
= past values of y that are used as features (X) to forecast y*
= observations, past or future, neither part of window nor forecast.
Assume we have the following training data (14 observations):
|----------------------------| | * * * * * * * * * * * * * *| |----------------------------|
And want to forecast with
window_length = 9
andfh = [2, 4]
.By construction, a recursive reducer always targets the first data point after the window, irrespective of the forecasting horizons requested. In the example the following 5 windows are created:
|----------------------------| | x x x x x x x x x y * * * *| | * x x x x x x x x x y * * *| | * * x x x x x x x x x y * *| | * * * x x x x x x x x x y *| | * * * * x x x x x x x x x y| |----------------------------|
Direct Reducers will create multiple models, one for each forecasting horizon. With the argument
windows_identical = True
(default) the windows used to train the model are defined by the maximum forecasting horizon. Only two complete windows can be defined in this examplefh = 4
(maximum offh = [2, 4]
):|----------------------------| | x x x x x x x x x * * * y *| | * x x x x x x x x x * * * y| |----------------------------|
All other forecasting horizons will also use those two (maximal) windows.
fh = 2
:|----------------------------| | x x x x x x x x x * y * * *| | * x x x x x x x x x * y * *| |----------------------------|
With
windows_identical = False
we drop the requirement to use the same windows for each of the direct models, so more windows can be created for horizons other than the maximum forecasting horizon.fh = 2
:|----------------------------| | x x x x x x x x x * y * * *| | * x x x x x x x x x * y * *| | * * x x x x x x x x x * y *| | * * * x x x x x x x x x * y| |----------------------------|
fh = 4
:|----------------------------| | x x x x x x x x x * * * y *| | * x x x x x x x x x * * * y| |----------------------------|
Use
windows_identical = True
if you want to compare the forecasting performance across different horizons, since all models trained will use the same windows. Usewindows_identical = False
if you want to have the highest forecasting accuracy for each forecasting horizon.- Parameters:
- estimatoran estimator instance, can be:
scikit-learn regressor or interface compatible
sktime time series regressor
skpro tabular probabilistic supervised regressor, only for direct reduction this will result in a probabilistic forecaster
- strategystr, optional (default=”recursive”)
The strategy to generate forecasts. Must be one of “direct”, “recursive” or “multioutput”.
- window_lengthint, optional (default=10)
Window length used in sliding window transformation.
- scitypestr, optional (default=”infer”)
Legacy argument for downwards compatibility, should not be used.
make_reduction
will automatically infer the correct type ofestimator
. This internal inference can be force-overridden by thescitype
argument. Must be one of “infer”, “tabular-regressor” or “time-series-regressor”. If the scitype cannot be inferred, this is a bug and should be reported.- transformers: list of transformers (default = None)
A suitable list of transformers that allows for using an en-bloc approach with make_reduction. This means that instead of using the raw past observations of y across the window length, suitable features will be generated directly from the past raw observations. Currently only supports WindowSummarizer (or a list of WindowSummarizers) to generate features e.g. the mean of the past 7 observations. Currently only works for RecursiveTimeSeriesRegressionForecaster.
- pooling: str {“local”, “global”}, optional
Specifies whether separate models will be fit at the level of each instance (local) of if you wish to fit a single model to all instances (“global”). Currently only works for RecursiveTimeSeriesRegressionForecaster.
- windows_identical: bool, (default = True)
Direct forecasting only. Specifies whether all direct models use the same X windows from y (True: Number of windows = total observations + 1 - window_length - maximum forecasting horizon) or a different number of X windows depending on the forecasting horizon (False: Number of windows = total observations + 1 - window_length - forecasting horizon). See pictionary below for more information.
- Returns:
- forecasteran sktime forecaster object
the reduction forecaster, wrapping
estimator
class is determined by thestrategy
argument and type ofestimator
.
References
[1]Bontempi, Gianluca & Ben Taieb, Souhaib & Le Borgne, Yann-Aël. (2013). Machine Learning Strategies for Time Series Forecasting.
Examples
>>> from sktime.forecasting.compose import make_reduction >>> from sktime.datasets import load_airline >>> from sklearn.ensemble import GradientBoostingRegressor >>> y = load_airline() >>> regressor = GradientBoostingRegressor() >>> forecaster = make_reduction(regressor, window_length=15, strategy="recursive") >>> forecaster.fit(y) RecursiveTabularRegressionForecaster(...) >>> y_pred = forecaster.predict(fh=[1,2,3])