Recursive multi-step forecasting with exogenous variables¶
ForecasterAutoreg and ForecasterAutoregCustom allow to include exogenous variables as predictors as long as their future values are known, since they must be included during the predict process.
When using exogenous variables in recursive multi-step forecasting, their values should be aligned so that y[i] is regressed on exog[i].
# Create and fit forecaster# ==============================================================================forecaster=ForecasterAutoreg(regressor=Ridge(),lags=15)forecaster.fit(y=data_train['y'],exog=data_train[['exog_1','exog_2']].values)forecaster
If the Forecaster has been trained with exogenous variables, they shlud be provided when predictiong.
1 2 3 4 5 6 7 8 910
# Predict# ==============================================================================steps=36predictions=forecaster.predict(steps=steps,exog=data_test[['exog_1','exog_2']].values)# Add datetime index to predictionspredictions=pd.Series(data=predictions,index=data_test.index)predictions.head(3)
# When using as regressor LinearRegression, Ridge or Lassoforecaster.get_coef()# When using as regressor RandomForestRegressor or GradientBoostingRegressor# forecaster.get_feature_importances()