Skip to content

ForecasterAutoregMultiOutput

class
skforecast.ForecasterAutoregMultiOutput.ForecasterAutoregMultiOutput.ForecasterAutoregMultiOutput(regressor, steps, lags)
Bases
skforecast.ForecasterBase.ForecasterBase.ForecasterBase

This class turns any regressor compatible with the scikit-learn API into a autoregressive multi-output forecaster. A separate model is created for each forecast time step. See Notes for more details.

Parameters
  • regressor (regressor or pipeline compatible with the scikit-learn API) An instance of a regressor or pipeline compatible with the scikit-learn API.
  • steps (int) Maximum number of future steps the forecaster will predict when using method predict(). Since a different model is created for each step, this value should be defined before training.
  • lags (int, list, 1d numpy ndarray, range) Lags used as predictors. Index starts at 1, so lag 1 is equal to t-1. int: include lags from 1 to lags (included). list, numpy ndarray or range: include only lags present in lags.
Attributes
  • X_train_col_names (tuple) Names of columns of the matrix created internally for training.
  • creation_date (str) Date of creation.
  • exog_col_names (tuple) Names of columns of exog if exog used in training was a pandas DataFrame.
  • exog_type (type) Type of exogenous variable/s used in training.
  • fit_date (str) Date of last fit.
  • fitted (Bool) Tag to identify if the regressor has been fitted (trained).
  • included_exog (bool) If the forecaster has been trained using exogenous variable/s.
  • index_freq (str) Frequency of Index of the input used in training.
  • index_type (type) Type of index of the input used in training.
  • lags (numpy ndarray) Lags used as predictors.
  • last_window (pandas Series) Last window the forecaster has seen during trained. It stores the values needed to predict the next step right after the training data.
  • max_lag (int) Maximum value of lag included in lags.
  • regressor (regressor or pipeline compatible with the scikit-learn API) An instance of a regressor or pipeline compatible with the scikit-learn API. One instance of this regressor is trainned for each step. All them are stored in self.regressors_.
  • regressors_ (dict) Dictionary with regressors trained for each step.
  • skforcast_version (str) Version of skforecast library used to create the forecaster.
  • steps (int) Number of future steps the forecaster will predict when using method predict(). Since a different model is created for each step, this value should be defined before training.
  • training_range (pandas Index) First and last index of samples used during training.
  • window_size (int) Size of the window needed to create the predictors. It is equal to max_lag.

Notes

A separate model is created for each forecast time step. It is important to note that all models share the same configuration of parameters and hyperparameters.

Methods
  • __repr__() (str) Information displayed when a ForecasterAutoregMultiOutput object is printed.
  • create_train_X_y(y, exog) (X_train : pandas DataFrame, shape (len(y) - self.max_lag, len(self.lags) + exog.shape[1]*steps)) Create training matrices from univariate time series and exogenous variables. The resulting matrices contain the target variable and predictors needed to train all the forecaster (one per step).
  • filter_train_X_y_for_step(step, X_train, y_train) (X_train_step : pandas DataFrame) Select columns needed to train a forcaster for a specific step. The input matrices should be created with created with create_train_X_y().
  • fit(y, exog) (None) Training Forecaster.
  • get_coef(step) (coef : pandas DataFrame) Return estimated coefficients for the regressor stored in the forecaster for a specific step. Since a separate model is created for each forecast time step, it is necessary to select the model from which retrieve the information.
  • get_feature_importance(step) (feature_importance : pandas DataFrame) Return impurity-based feature importance of the model stored in the forecaster for a specific step. Since a separate model is created for each forecast time step, it is necessary to select the model from which retrieve information.
  • predict(steps, last_window, exog) (predictions : pandas Series) Predict n steps ahead.
  • set_lags(lags) (self) Set new value to the attribute lags. Attributes max_lag and window_size are also updated.
  • set_params(**params) (self) Set new values to the parameters of the scikit learn model stored in the forecaster. It is important to note that all models share the same configuration of parameters and hyperparameters.
  • summary() Show forecaster information.
method
summary()

Show forecaster information.

method
__repr__() → str

Information displayed when a ForecasterAutoregMultiOutput object is printed.

method
create_train_X_y(y, exog=None)

Create training matrices from univariate time series and exogenous variables. The resulting matrices contain the target variable and predictors needed to train all the forecaster (one per step).

Parameters
  • y (pandas Series) Training time series.
  • exog (pandas Series, pandas DataFrame, default `None`) Exogenous variable/s included as predictor/s. Must have the same number of observations as y and their indexes must be aligned.
Returns (X_train : pandas DataFrame, shape (len(y) - self.max_lag, len(self.lags) + exog.shape[1]*steps))

Pandas DataFrame with the training values (predictors) for each step.

ain : pd.DataFrame, shape (len(y) - self.max_lag, ) Values (target) of the time series related to each row of X_train for each step.

method
filter_train_X_y_for_step(step, X_train, y_train)

Select columns needed to train a forcaster for a specific step. The input matrices should be created with created with create_train_X_y().

Parameters
  • step (int) step for which columns must be selected selected. Starts at 0.
  • X_train (pandas DataFrame) Pandas DataFrame with the training values (predictors).
  • y_train (pandas Series) Values (target) of the time series related to each row of X_train.
Returns (X_train_step : pandas DataFrame)

Pandas DataFrame with the training values (predictors) for step.

ain_step : pandas Series, shape (len(y) - self.max_lag) Values (target) of the time series related to each row of X_train.

method
fit(y, exog=None)

Training Forecaster.

Parameters
  • y (pandas Series) Training time series.
  • exog (pandas Series, pandas DataFrame, default `None`) Exogenous variable/s included as predictor/s. Must have the same number of observations as y and their indexes must be aligned so that y[i] is regressed on exog[i].
method
predict(steps=None, last_window=None, exog=None)

Predict n steps ahead.

Parameters
  • steps (int, None, default `None`) Predict n steps ahead. steps must lower or equal to the value of steps defined when initializing the forecaster. If None, as many steps as defined in the initialization are predicted.
  • last_window (pandas Series, default `None`) Values of the series used to create the predictors (lags) need in the first iteration of prediction (t + 1).
    If last_window = None, the values stored inself.last_window are used to calculate the initial predictors, and the predictions start right after training data.
  • exog (pandas Series, pandas DataFrame, default `None`) Exogenous variable/s included as predictor/s.
Returns (predictions : pandas Series)

Predicted values.

method
set_params(**params)

Set new values to the parameters of the scikit learn model stored in the forecaster. It is important to note that all models share the same configuration of parameters and hyperparameters.

method
set_lags(lags)

Set new value to the attribute lags. Attributes max_lag and window_size are also updated.

method
get_coef(step)

Return estimated coefficients for the regressor stored in the forecaster for a specific step. Since a separate model is created for each forecast time step, it is necessary to select the model from which retrieve the information.

Only valid when regressor stores internally the feature coefficients in the attribute coef_.

Parameters
  • step (int) Model from which retrieve information (a separate model is created for each forecast time step).
Returns (coef : pandas DataFrame)

Value of the coefficients associated with each predictor.

method
get_feature_importance(step)

Return impurity-based feature importance of the model stored in the forecaster for a specific step. Since a separate model is created for each forecast time step, it is necessary to select the model from which retrieve information.

Only valid when the forecaster has been trained using GradientBoostingRegressor, RandomForestRegressor or HistGradientBoostingRegressor as regressor.

Parameters
  • step (int) Model from which retrieve information (a separate model is created for each forecast time step).
Returns (feature_importance : pandas DataFrame)

Impurity-based feature importance associated with each predictor.