Skip to content

ForecasterAutoregMultiOutput

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

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 compatible with the scikit-learn API) An instance of a regressor compatible with the scikit-learn API.
  • steps (int) Number of future steps the forecaster will predict when using method predict(). Since a diferent model is created for each step, this value should be defined before training.
  • lags (int, list, 1D np.array, 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 or np.array: include only lags present in lags.
Attributes
  • exog_shape (tuple) Shape of exog used in training.
  • exog_type (type) Type used for the exogenous variable/s.
  • included_exog (bool) If the forecaster has been trained using exogenous variable/s.
  • lags (1D np.array) Lags used as predictors.
  • last_window (1D np.ndarray) Last time window the forecaster has seen when trained. It stores the values needed to calculate the lags used to predict the next step after the training data.
  • max_lag (int) Maximum value of lag included in lags.
  • regressor (regressor compatible with the scikit-learn API) An instance of regressor compatible with the scikit-learn API. One instance of this regressor is trainned for each step. All them are stored in slef.regressors_.
  • regressors_ (dict) Dictionary with regressors trained for each step.
  • steps (int) Number of future steps the forecaster will predict when using method predict(). Since a diferent model is created for each step, this value should be defined before training.

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 hiperparameters.

Methods
  • __repr__() (str) Information displayed when a ForecasterAutoreg object is printed.
  • create_lags(y) (X_data : 2D np.ndarray) Transforms a time series into two 2D arrays of pairs predictor-response.
  • create_train_X_y(y, exog) (X_train : 2D np.ndarray, shape (len(y) - self.max_lag, len(self.lags) + exog.shape[1]*steps)) Create training matrices X, y. The created 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 : 2D np.ndarray) Select columns needed to train a forcaster for a specific step. The imput matrices should be created with created with create_train_X_y().
  • fit(y, exog) (self : ForecasterAutoregMultiOutput) Training ForecasterAutoregMultiOutput
  • get_coef(step) (coef : 1D np.ndarray) Return estimated coefficients for the linear regression 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 retireve information.
  • get_feature_importances(step) (feature_importances : 1D np.ndarray) Return impurity-based feature importances 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 retireve information.
  • predict(last_window, exog, steps) (predictions : 1D np.array, shape (steps,)) Multi-step prediction. The number of future steps predicted is defined when ininitializing the forecaster, argument steps not used, present here for API consistency by convention.
  • set_lags(lags) (self) Set new value to the attribute lags. Attribute max_lag is 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 hiperparameters.
method
__repr__() → str

Information displayed when a ForecasterAutoreg object is printed.

method
create_lags(y)

Transforms a time series into two 2D arrays of pairs predictor-response.

Notice that the returned matrix X_data, contains the lag 1 in the first column, the lag 2 in the second column and so on.

Parameters
  • y (1D np.ndarray, pd.Series) Training time series.
Returns (X_data : 2D np.ndarray)

2D array with the lag values (predictors).

ta : 2D np.ndarray Values of the time series related to each row of X_data.

method
create_train_X_y(y, exog=None)

Create training matrices X, y. The created matrices contain the target variable and predictors needed to train all the forecaster (one per step).

Parameters
  • y (1D np.ndarray, pd.Series) Training time series.
  • exog (np.ndarray, pd.Series, pd.DataFrame, default `None`) Exogenous variable/s included as predictor/s. Must have the same number of observations as y and should be aligned so that y[i] is regressed on exog[i].
Returns (X_train : 2D np.ndarray, shape (len(y) - self.max_lag, len(self.lags) + exog.shape[1]*steps))

2D array with the training values (predictors).

ain : 1D np.ndarray, shape (len(y) - self.max_lag) Values (target) of the time series related to each row of X_train.

method
filter_train_X_y_for_step(step, X_train, y_train)

Select columns needed to train a forcaster for a specific step. The imput 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 (2D np.ndarray) 2D array with the training values (predictors).
  • y_train (1D np.ndarray) Values (target) of the time series related to each row of X_train.
Returns (X_train_step : 2D np.ndarray)

2D array with the training values (predictors) for step.

ain_step : 1D np.ndarray, 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 ForecasterAutoregMultiOutput

Parameters
  • y (1D np.ndarray, pd.Series) Training time series.
  • exog (np.ndarray, pd.Series, pd.DataFrame, default `None`) Exogenous variable/s included as predictor/s. Must have the same number of observations as y and should be aligned so that y[i] is regressed on exog[i].
Returns (self : ForecasterAutoregMultiOutput)

Trained ForecasterAutoregMultiOutput

method
predict(last_window=None, exog=None, steps=None)

Multi-step prediction. The number of future steps predicted is defined when ininitializing the forecaster, argument steps not used, present here for API consistency by convention.

Returns (predictions : 1D np.array, shape (steps,))

Values predicted.

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 hiperparameters.

Parameters
  • params (dict) Parameters values.
method
set_lags(lags)

Set new value to the attribute lags. Attribute max_lag is also updated.

Parameters
  • Lags used as predictors. Index starts at 1, so lag 1 is equal to t-1. int: include lags from 1 to lags. list or np.array: include only lags present in lags.
method
get_coef(step)

Return estimated coefficients for the linear regression 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 retireve information.

Only valid when the forecaster has been trained using as regressor:LinearRegression(),Lasso()orRidge()`.

Parameters
  • step (int) Model from which retireve information (a separate model is created for each forecast time step).
Returns (coef : 1D np.ndarray)

Value of the coefficients associated with each predictor (lag). Coefficients are aligned so that coef[i] is the value associated with self.lags[i].

method
get_feature_importances(step)

Return impurity-based feature importances 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 retireve information.

Only valid when the forecaster has been trained using regressor=GradientBoostingRegressor() or regressor=RandomForestRegressor.

Parameters
  • step (int) Model from which retireve information (a separate model is created for each forecast time step).
Returns (feature_importances : 1D np.ndarray)

Impurity-based feature importances associated with each predictor (lag). Values are aligned so that feature_importances[i] is the value associated with self.lags[i].