ForecasterAutoreg and ForecasterAutoregCustom models follow a recursive prediction strategy in which, each new prediction, builds on the previous prediction. An alternative is to train a model for each step that has to be predicted. This strategy, commonly known as direct multistep forecasting, is computationally more expensive than the recursive since it requires training several models. However, in some scenarios, it achieves better results. This type of model can be obtained with the ForecasterAutoregMultiOutput class and can also include one or multiple exogenous variables.
In order to train a ForecasterAutoregMultiOutput a different training matrix is created for each model.
# Create and fit forecaster# ==============================================================================forecaster=ForecasterAutoregMultiOutput(regressor=make_pipeline(StandardScaler(),Ridge()),steps=36,lags=15)forecaster.fit(y=data_train)forecaster
1 2 3 4 5 6 7 8 91011121314151617
============================
ForecasterAutoregMultiOutput
============================
Regressor: Pipeline(steps=[('standardscaler', StandardScaler()), ('ridge', Ridge())])
Lags: [ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15]
Window size: 15
Maximum steps predicted: 36
Included exogenous: False
Type of exogenous variable: None
Exogenous variables names: None
Training range: [Timestamp('1991-07-01 00:00:00'), Timestamp('2005-06-01 00:00:00')]
Training index type: DatetimeIndex
Training index frequency: MS
Regressor parameters: {'standardscaler__copy': True, 'standardscaler__with_mean': True, 'standardscaler__with_std': True, 'ridge__alpha': 1.0, 'ridge__copy_X': True, 'ridge__fit_intercept': True, 'ridge__max_iter': None, 'ridge__normalize': 'deprecated', 'ridge__positive': False, 'ridge__random_state': None, 'ridge__solver': 'auto', 'ridge__tol': 0.001}
Creation date: 2021-12-07 21:30:45
Last fit date: 2021-12-07 21:30:45
Skforecast version: 0.4.0
Two steps are needed. One to create the whole training matrix and a second one to subset the data needed for each model (step).
123456789
X,y=forecaster.create_train_X_y(data_train)# X and y to train model for step 1X_1,y_1=forecaster.filter_train_X_y_for_step(step=1,X_train=X,y_train=y,)print(X_1.head(4))print(y_1.head(4))