This module contains the base class for all forecasters in spotforecast2_safe and spotforecast. All forecasters should specify all the parameters that can be set at the class level in their init.
Examples
import numpy as npimport pandas as pdfrom sklearn.linear_model import Ridgefrom spotforecast2_safe.forecaster.base import ForecasterBaseclass MyForecaster(ForecasterBase):def__init__(self, estimator):self.estimator = estimatorself.__spotforecast_tags__ = {'hide_lags': True}def create_train_X_y(self, y, exog=None):return pd.DataFrame(), pd.Series(dtype=float)def fit(self, y, exog=None):passdef predict(self, steps, last_window=None, exog=None):return pd.Series(np.zeros(steps))def set_params(self, params):passforecaster = MyForecaster(estimator=Ridge())print(repr(forecaster))
All forecasters should specify all the parameters that can be set at the class level in their init.
Attributes
Name
Type
Description
spotforecast_tags
Dictionary with forecaster tags that characterize the behavior of the forecaster.
Examples
import inspectfrom spotforecast2_safe.forecaster.base import ForecasterBaseabstract_methods = [ m[0] for m in inspect.getmembers(ForecasterBase, predicate=inspect.isabstract)]print(abstract_methods)
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]. Default is None.
None
Returns
Name
Type
Description
None
None
Examples
import numpy as npimport pandas as pdfrom sklearn.linear_model import Ridgefrom spotforecast2_safe.forecaster.recursive import ForecasterRecursiveforecaster = ForecasterRecursive(estimator=Ridge(), lags=3)y = pd.Series(np.arange(10), name='y')forecaster.fit(y)print(forecaster.is_fitted)
True
get_tags
forecaster.base.ForecasterBase.get_tags()
Return the tags that characterize the behavior of the forecaster.
Series values used to create the predictors (lags) needed in the first iteration of the prediction (t + 1). If None, the values stored in last_window are used to calculate the initial predictors, and the predictions start right after training data. Default is None.
Lags used as predictors. Index starts at 1, so lag 1 is equal to t-1. If int: include lags from 1 to lags (included). If list, 1d numpy ndarray, or range: include only lags present in lags, all elements must be int. If None: no lags are included as predictors. Default is None.
None
Returns
Name
Type
Description
None
None
Examples
from sklearn.linear_model import Ridgefrom spotforecast2_safe.forecaster.recursive import ForecasterRecursiveforecaster = ForecasterRecursive(estimator=Ridge(), lags=3)forecaster.set_lags(lags=5)print(forecaster.lags)
[1 2 3 4 5]
set_params
forecaster.base.ForecasterBase.set_params(params)
Set new values to the parameters of the scikit-learn model stored in the forecaster.
Instance or list of instances used to create window features. Window features are created from the original time series and are included as predictors. Default is None.