ForecasterAutoregCustom
¶
skforecast.ForecasterAutoregCustom.
ForecasterAutoregCustom
(
regressor
, fun_predictors
, window_size
)
This class turns any regressor compatible with the scikit-learn API into a recursive (multi-step) forecaster with a custom function to create predictors.
regressor
(any regressor compatible with the scikit-learn API) — An instance of a regressor compatible with the scikit-learn API.fun_predictors
(Callable) — Function that takes a time series window as an argument and returns annp.array
with the predictors associated with that window.window_size
(int) — Size of the window needed byfun_predictors
to create the predictors.
exog_shape
(tuple) — Shape of exog used in training.exog_type
(type) — Type used for the exogenous variable/s.fitted
(Bool) — Tag to identify if the estimator is fitted.fun_predictors
(Callable) — Function that takes a time series window as an argument and returns annp.array
with the predictors associated with that window.in_sample_residuals
(np.ndarray) — Residuals of the model when predicting training data. Only stored up to 1000 values.included_exog
(bool) — If the forecaster has been trained using exogenous variable/s.last_window
(1D np.ndarray) — Last time window the forecaster has seen when trained. It stores the values needed to calculate the predictors for the nextstep
after the training data.out_sample_residuals
(np.ndarray) — Residuals of the model when predicting non training data. Only stored up to 1000 values.regressor
(regressor compatible with the scikit-learn API) — An instance of a regressor compatible with the scikit-learn API.window_size
(int) — Size of the window needed byfun_predictors
to create the predictors.
__repr__
(
)
(str) — Information displayed when a ForecasterAutoregCustom object is printed.create_train_X_y
(
y
,exog
)
(X_train : 2D np.ndarray, shape (len(y) - self.max_lag, len(self.lags))) — Create training matrices X, yfit
(
y
,exog
)
(self : ForecasterAutoregCustom) — Training ForecasterAutoregCustomget_coef
(
)
(coef : 1D np.ndarray) — Return estimated coefficients for the linear regression model stored in the forecaster. Only valid when the forecaster has been trained using asregressor:
LinearRegression(),
Lasso()or
Ridge()`.get_feature_importances
(
)
(feature_importances : 1D np.ndarray) — Return impurity-based feature importances of the model stored in the forecaster. Only valid when the forecaster has been trained usingregressor=GradientBoostingRegressor()
orregressor=RandomForestRegressor
.predict
(
steps
,last_window
,exog
)
(predicciones : 1D np.array, shape (steps,)) — Iterative process in which, each prediction, is used as a predictor for the next step.predict_interval
(
steps
,last_window
,exog
,interval
,n_boot
,in_sample_residuals
)
(predictions : np.array, shape (steps, 3)) — Iterative process in which, each prediction, is used as a predictor for the next step and bootstrapping is used to estimate prediction intervals. Both, predictions and intervals, are returned.set_out_sample_residuals
(
residuals
,append
)
(self) — Set new values to the attributeout_sample_residuals
. Out of sample residuals are meant to be calculated using observations that did not participate in the training process.set_params
(
**params
)
(self) — Set new values to the parameters of the scikit learn model stored in the ForecasterAutoregCustom.
__repr__
(
)
→ strInformation displayed when a ForecasterAutoregCustom object is printed.
create_train_X_y
(
y
, exog=None
)
Create training matrices X, y
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
.
fit
(
y
, exog=None
)
Training ForecasterAutoregCustom
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 ForecasterAutoregCustom
predict
(
steps
, last_window=None
, exog=None
)
Iterative process in which, each prediction, is used as a predictor for the next step.
steps
(int) — Number of future steps predicted.last_window
(1D np.ndarray, pd.Series, default `None`) — Values of the series used to create the predictors need in the first iteration of predictiont (t + 1).
Iflast_window = None
, the values stored inself.last_window
are used to calculate the initial predictors, and the predictions start right after training data.exog
(np.ndarray, pd.Series, pd.DataFrame, default `None`) — Exogenous variable/s included as predictor/s.
Values predicted.
predict_interval
(
steps
, last_window=None
, exog=None
, interval=[5, 95]
, n_boot=500
, in_sample_residuals=True
)
Iterative process in which, each prediction, is used as a predictor for the next step and bootstrapping is used to estimate prediction intervals. Both, predictions and intervals, are returned.
steps
(int) — Number of future steps predicted.last_window
(1D np.ndarray, pd.Series, default `None`) — Values of the series used to create the predictors need in the first iteration of predictiont (t + 1).
Iflast_window = None
, the values stored inself.last_window
are used to calculate the initial predictors, and the predictions start right after training data.exog
(np.ndarray, pd.Series, pd.DataFrame, default `None`) — Exogenous variable/s included as predictor/s.interval
(list, default `[5, 100]`) — Confidence of the prediction interval estimated. Sequence of percentiles to compute, which must be between 0 and 100 inclusive.n_boot
(int, default `500`) — Number of bootstrapping iterations used to estimate prediction intervals.in_sample_residuals
(bool, default `True`) — IfTrue
, residuals from the training data are used as proxy of prediction error to create prediction intervals. IfFalse
, out of sample residuals are used. In the latter case, the user shoud have calculated and stored the residuals within the forecaster (seeset_out_sample_residuals()
).
Values predicted by the forecaster and their estimated interval. Column 0 = predictions Column 1 = lower bound interval Column 2 = upper bound interval
Notes
More information about prediction intervals in forecasting: https://otexts.com/fpp2/prediction-intervals.html Forecasting: Principles and Practice (2nd ed) Rob J Hyndman and George Athanasopoulos.
set_params
(
**params
)
Set new values to the parameters of the scikit learn model stored in the ForecasterAutoregCustom.
params
(dict) — Parameters values.
set_out_sample_residuals
(
residuals
, append=True
)
Set new values to the attribute out_sample_residuals
. Out of sample
residuals are meant to be calculated using observations that did not
participate in the training process.
append
(bool, default `True`) — IfTrue
, new residuals are added to the once already stored in the attributeout_sample_residuals
. Once the limit of 1000 values is reached, no more values are appended. If False,out_sample_residuals
is overwrited with the new residuals.params
(1D np.ndarray) — Values of residuals. If len(residuals) > 1000, only a random sample of 1000 values are stored.
get_coef
(
)
Return estimated coefficients for the linear regression model stored in
the forecaster. Only valid when the forecaster has been trained using
as regressor:
LinearRegression(),
Lasso()or
Ridge()`.
Value of the coefficients associated with each predictor.
Coefficients are aligned so that coef[i]
is the value associated
with predictor i returned by self.create_predictors
.
get_feature_importances
(
)
Return impurity-based feature importances of the model stored in the
forecaster. Only valid when the forecaster has been trained using
regressor=GradientBoostingRegressor()
or regressor=RandomForestRegressor
.
Impurity-based feature importances associated with each predictor.
Values are aligned so that feature_importances[i]
is the value
associated with predictor i returned by self.create_predictors
.