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=GradientBoostingRegressor(),steps=36,lags=15)forecaster.fit(y=data_train)forecaster
If the Forecaster has been trained with exogenous variables, they shlud be provided when predictiong.
1234567
# Predict# ==============================================================================steps=36predictions=forecaster.predict(steps=steps)# Add datetime index to predictionspredictions=pd.Series(data=predictions,index=data_test.index)predictions.head(3)
Since ForecasterAutoregMultiOutput fits one model per step,it is necessary to specify from which model retrieve its feature importance.
12345
# When using as regressor LinearRegression, Ridge or Lasso# forecaster.get_coef()# When using as regressor RandomForestRegressor or GradientBoostingRegressorforecaster.get_feature_importances(step=1)
Two steps are needed. One to create the whole training matrix and a second one to subset the data needed for each model (step).
1234567
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,)