ForecasterAutoregCustom
¶
skforecast.ForecasterAutoregCustom.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
(regressor or pipeline compatible with the scikit-learn API) — An instance of a regressor or pipeline compatible with the scikit-learn API.fun_predictors
(Callable) — Function that takes a numpy ndarray as a window of values as input and returns a numpy ndarray with the predictors associated with that window.window_size
(int) — Size of the window needed byfun_predictors
to create the predictors.
X_train_col_names
(list) — Names of columns of the matrix created internally for training.create_predictors
(Callable) — Function that takes a numpy ndarray as a window of values as input and returns a numpy ndarray with the predictors associated with that window.creation_date
(str) — Date of creation.exog_col_names
(list) — Names of columns ofexog
ifexog
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).in_sample_residuals
(numpy 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.index_freq
(str) — Frequency of Index of the input used in training.index_type
(type) — Type of index of the input used in training.last_window
(pandas Series) — Last window the forecaster has seen during trained. It stores the values needed to predict the nextstep
right after the training data.out_sample_residuals
(numpy 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.skforcast_version
(str) — Version of skforecast library used to create the forecaster.source_code_create_predictors
(str) — Source code of the custom function used to create the predictors.training_range
(pandas Index) — First and last values of index of the data used during training.window_size
(int) — Size of the window needed byfun_predictors
to create the predictors.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 : pandas DataFrame) — Create training matrices from univariate time series.fit
(
y
,exog
)
(None) — Training Forecaster.get_coef
(
)
(coef : pandas DataFrame) — Return estimated coefficients for the regressor stored in the forecaster. Only valid when regressor stores internally the feature coefficients in the attributecoef_
.get_feature_importance
(
)
(feature_importance : pandas DataFrame) — Return feature importance of the regressor stored in the forecaster. Only valid when regressor stores internally the feature importance in the attributefeature_importances_
.predict
(
steps
,last_window
,exog
)
(predictions : pandas Series) — Predict n steps ahead. It is an recursive process in which, each prediction, is used as a predictor for the next step.predict_interval
(
steps
,last_window
,exog
,interval
,n_boot
,random_state
,in_sample_residuals
)
(predictions : pandas DataFrame) — 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_lags
(
lags
)
(self) — Set new value to the attributelags
. Attributesmax_lag
andwindow_size
are also updated.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.summary
(
)
— Show forecaster information.
set_lags
(
lags
)
Set new value to the attribute lags
.
Attributes max_lag
and window_size
are also updated.
summary
(
)
Show forecaster information.
__repr__
(
)
→ strInformation displayed when a ForecasterAutoregCustom object is printed.
create_train_X_y
(
y
, exog=None
)
Create training matrices from univariate time series.
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 asy
and their indexes must be aligned.
Pandas DataFrame with the training values (predictors).
ain : pandas Series
Values (target) of the time series related to each row of X_train
.
fit
(
y
, exog=None
)
Training Forecaster.
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 asy
and their indexes must be aligned so that y[i] is regressed on exog[i].
predict
(
steps
, last_window=None
, exog=None
)
Predict n steps ahead. It is an recursive process in which, each prediction, is used as a predictor for the next step.
steps
(int) — Number of future steps 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).
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
(pandas Series, pandas DataFrame, default `None`) — Exogenous variable/s included as predictor/s.
Predicted values.
predict_interval
(
steps
, last_window=None
, exog=None
, interval=[5, 95]
, n_boot=500
, random_state=123
, 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
(pandas Series, default `None`) — Values of the series used to create the predictors (lags) needed in the first iteration of prediction (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
(pandas Series, pandas DataFrame, default `None`) — Exogenous variable/s included as predictor/s.interval
(list, default `[5, 95]`) — 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.random_state
(int, default 123) — Sets a seed to the random generator, so that boot intervals are always deterministic.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 should have calculated and stored the residuals within the forecaster (seeset_out_sample_residuals()
).
Values predicted by the forecaster and their estimated interval: column pred = predictions. column lower_bound = lower bound of the interval. column upper_bound = upper bound interval of the 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.
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 overwritten 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 regressor stored in the forecaster.
Only valid when regressor stores internally the feature coefficients in
the attribute coef_
.
Value of the coefficients associated with each predictor.
get_feature_importance
(
)
Return feature importance of the regressor stored in the
forecaster. Only valid when regressor stores internally the feature
importance in the attribute feature_importances_
.
Feature importance associated with each predictor.