ForecasterAutoregMultiOutput
¶
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.
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 methodpredict()
. 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 tolags
(included).list
ornp.array
: include only lags present inlags
.
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 nextstep
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 inslef.regressors_
.regressors_
(dict) — Dictionary with regressors trained for each step.steps
(int) — Number of future steps the forecaster will predict when using methodpredict()
. 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.
__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 withcreate_train_X_y()
.fit
(
y
,exog
)
(self : ForecasterAutoregMultiOutput) — Training ForecasterAutoregMultiOutputget_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, argumentsteps
not used, present here for API consistency by convention.set_lags
(
lags
)
(self) — Set new value to the attributelags
. Attributemax_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.
__repr__
(
)
→ strInformation displayed when a ForecasterAutoreg object is printed.
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.
y
(1D np.ndarray, pd.Series) — Training time series.
2D array with the lag values (predictors).
ta : 2D np.ndarray
Values of the time series related to each row of X_data
.
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).
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 asy
and should be aligned so that y[i] is regressed on exog[i].
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
.
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()
.
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 ofX_train
.
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
.
fit
(
y
, exog=None
)
Training ForecasterAutoregMultiOutput
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 asy
and should be aligned so that y[i] is regressed on exog[i].
Trained ForecasterAutoregMultiOutput
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.
Values predicted.
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.
params
(dict) — Parameters values.
set_lags
(
lags
)
Set new value to the attribute lags
.
Attribute max_lag
is also updated.
Lags used as predictors. Index starts at 1, so lag 1 is equal to t-1.
—int
: include lags from 1 tolags
.list
ornp.array
: include only lags present inlags
.
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()or
Ridge()`.
step
(int) — Model from which retireve information (a separate model is created for each forecast time step).
Value of the coefficients associated with each predictor (lag).
Coefficients are aligned so that coef[i]
is the value associated
with self.lags[i]
.
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
.
step
(int) — Model from which retireve information (a separate model is created for each forecast time step).
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]
.