Scitype interface specification: forecaster
WARNING: this is outdated, interface has been refactored since - refer to sphinx docs and current extension templates
This section contains a copy-pasteable checklist for quick extension reference.
Please refer to the full design and extension guidelines below.
- the estimator should inherit from
sktime
'sBaseForecaster
. TheBaseForecaster
class inherits fromsklearn
'sBaseEstimator
class, so satisfies the template inheritance requirements. - the estimator must implement
fit(self, y, X=None, fh=None)
. This is first time model fitting. Arguments arey : pd.Series
initial time series observations;X : pd.DataFrame
exogeneous time series; optional:fh
:int
,list
,np.array
, orForecastingHorizon
object - forecasting horizon. -
fit
must set the_is_fitted
attribute toTrue
. - optionlly, the estimator overrides
update(self, y, X=None, update_params=True)
. This is model update with additional data afterfit
has been called. Arguments arey : pd.Series
additional time series observations;X : pd.DataFrame
exogeneous time series;update_params : Boolean
controls whether model parameters are updated, or only data is ingested. If not overridden,update
uses default logic fromBaseForecaster
which callsfit
. -
fit
andupdate
must set the attributecutoff
:int
ornumpy.datetime64
to most recent time stamp iny
. Ifupdate
is inherited, this is automatically done;fit
needs to implement this explicitly. - the estimator must implement
predict(self, fh=None, X=None)
. This is prediction afterfit
has been called. Arguments areX : pd.DataFrame
exogeneous time series; mandatory:fh
:int
,list
,np.array
, orForecastingHorizon
object - forecasting horizon. Returns a forecastpd.Series
at time indicesfh
. - consider using
_SktimeForecaster
and_OptionalForecastingHorizonMixin
for extension._SktimeForecaster
provides additional templating functionality; it also inherits fromBaseEstimator
andBaseForecaster
, so inheriting from_SktimeForecaster
can replace inheriting from the two latter classes. - mandatory input checks using
check_y_X
,check_X
,check_y
,check_fh
should be performed infit
,predict
, andupdate
(where applicable)
Optional functionality:
-
return_pred_int
andalpha
return objects forpredict
- prediction intervals - custom
update_predict
method
Forecasters operate on the following conceptual data model with data objects:
- observation times
$t_1 < t_2 <\dots \in \mathbb{R}$ , also called time stamps below. - endogeneous observation values
$y_1, y_2,\dots \in E$ , where$E$ is a data frame row domain which may include missing data (usually but not necessarily$\mathbb{R}^n$ for some$n\in \mathbb{N}$ ). The value$y_i$ is interpreted to be observed at time$t_i$ ; we will alternatively write$y(t_i)$ for$y_i$ . - temporal exogeneous observation values
$x_1, x_2, dotx, \in E'$ , where$E'$ is a data frame row domain which may include missing data (usually but not necessarily$\mathbb{R}^{n'}$ for some$n'\in \mathbb{N}$ ). The value$x_i$ is interpreted to be observed at time$t_i$ ; we will alternatively write$x(t_i)$ for$x_i$ . - non-temporal exogeneous observation values
$x'_1, x'_2, dotx, \in E''$ , where$E''$ is a data frame row domain which may include missing data (usually but not necessarily$\mathbb{R}^{n'}$ for some$n'\in \mathbb{N}$ ). The value$x'_i$ is interpreted to be observed at time$t_i$ ; we will alternatively write$x'(t_i)$ for$x'_i$ .
Of all indices occurring above, there are potentially infinitely many.
The data model above does not distinguish whether data has been actually "observed"; it only specifies the objects that in-principle can be observed.
The endogeneous and temporal exogeneous values are assumed to be "temporal", i.e.,
A forecaster is a parametric entity object (or stateful object) that has the following state variables:
-
$\tau\in \mathbb{R}$ , called the cut-off. Intuitively,$\tau$ is the forecaster's present time, i.e., a "now-time" state variable. - a model representation, without any explicit domain specification.
A forecaster has two states:
- unfitted - in this state, no data has been ingested. In this state, the state variables are not set.
- fitted - in this state, some data has been ingested. In this state, a model representation and a cut-off are set.
A forecaster can transition from unfitted to fitted; once fitted, it remains fitted.
A forecaster has the following scitype-defining methods:
-
fit
- fitting, "first time ingesting of data". This method is invoked at some current time$T$ . This method gives the forecaster access to some$t_i$ , and some or all$x'(t_i)$ ; it also gives access to some$y(t_i), x(t_i)$ where$t_i\le T$ . The method updates the state variable$\tau \leftarrow T$ , stores a model representation, and sets the forecaster's state to fitted. Intuitively, invokingfit
models the first time behaviour when data is ingested to the forecaster. -
predict
- forecasting or prediction. This method requires the forecaster to be in fitted state. This method queries and outputs predictions$\widehat{y}(t'_i)$ for some$y(t'_i)$ . The query is passed to the method as the (finite length) sequence$t'_1,\dots, t'_N$ for which predictions are queried; the method returns the predictions$\widehat{y}(t'_i)$ . In addition, some or all$x'(t'_i)$ may be passed here. The state is not changed. It is not necessarily assumed that$t'_i > \tau$ for all$i$ , i.e., some predictions might be "hindcasts" instead of foreasts in the strict sense. -
update
- updating the forecaster with new data, "ingesting additional data", while time progresses. This method requires the forecaster to be in fitted state. This method is called at some time$T>\tau$ , and sets the state$\tau$ to the new current time$T$ . It gives the forecaster access to some additional$t_i$ , and some or all$x'(t_i)$ ; it also gives access to some$y(t_i), x(t_i)$ where$t_i\le T$ . The method updates the model representation. The state is not changed. Intuitively, invokingupdate
models the process of updating model representation as time progresses, ingesting additional data.
The concrete implementation of the three methods fit
, predict
, update
combined defines a specific forecaster; behaviour is possibly parametric, dependent on the same parameters as the forecaster.
Note: it is expressly not assumed nor excluded that ingesting data in multiple chunks through fit
and multiple uses of update
results in the same model representation as ingesting the same data as a singel chunk, through a single application of fit
.
In comparison to the fulll conceptual model, a number of restrictions apply to the conceptual model supported by the sktime
interface:
- support only for univariate endogenous observations, i.e.,
$E$ is a primitive value domain, i.e.,$E$ is finite (categorical) or$E=\mathbb{R}$ . This is a major restriction, and we aim to provide support for multivariate endogeneous observations in the future. - when ingesting data through
fit
, the latest timestamp is assumed to be identical with the present time; i.e., when ingesting data with times$t_1,\dots, t_N$ , the cut-off$\tau$ is always set to$t_N$ (this is not the case forupdate
) - no declarative distinction between temporal and non-temporal exogeneous observations.
This section describes the interface contract that any estimator following the forecaster scitype are expected to fulfil.
Forecasters are represented as classes.
State variables are represented as follows:
-
_is_fitted
:Boolean
; whether the model is in fitted state (True
) or unfitted (False
). - model representation is through any number of private variables. Variables corresponding to model state representation should start with underscore.
-
cutoff
:int
ornumpy.datetime64
; cut-off, models$\tau$
The core interface of forecasters consists of the following methods:
__init__(self, ...)
Behaviour: construction and initialization of estimator. Used for specification.
Requirements:
- hyper-parameters should be named arguments, and should be written to variables with identical name in
self
. - components should be
sklearn
estimators. -
__init__
should set the flag_is_fitted
toFalse
.
fit(self, y, X=None, fh=None)
Parameters:
-
y
:pd.Series
; this models the$y(t_i)$ and$t_i$ to which access is given infit
. The$y(t_i)$ are the entries ofy
, and$t_i$ arey.index
. -
X
:pd.DataFrame
; this models$x(t_i)$ and$x'(t_i)$ to which access is given infit
. The$x(t_i)$ and$x'(t_i)$ are the entries ofX
, with different components being the different variables ofX
. The$t_i$ areX.index
. -
fh
:int
,list
,np.array
, orForecastingHorizon
object; for some forecasters, the information on the query on predict already needs to be passed onfit
- this should be the same object, see below inpredict
.
Behaviour:
- fits a model and writes representation to any number of private variables representing the model to
self
. - sets the cut-off to the largest of the
$t_i$ passed iny
, i.e., the largest element ofy.index
- sets
_is_fitted
toTrue
- should have no side effects on arguments
Returns: self
predict(self, fh=None, X=None):
-
fh
:int
,list
,np.array
, orForecastingHorizon
object; encodes the query topredict
in the form of time indices$t_i$ at which to produce the predictions$\widehat{y}(t_i)$ , as predictions for unknown$y(t_i)$ . -
X
:pd.DataFrame
; this models$x'(t_i)$ to which access is given inpredict
. The$x'(t_i)$ are the entries ofX
, with different components being the different variables ofX
. The$t_i$ areX.index
. For easy implementation, it can be assumed that$x'(t_i)$ with$t_i>\tau$ are seen/passed only inpredict
.
Behaviour:
- accesses model representation and produces predictions
- should have no side effects on arguments
- should not change state variables
Returns:
-
y_pred
:pd.Series
: this models the predictions$\widehat{y}(t_i)$ and$t_i$ for the$t_i$ encoded infh
. The$\widehat{y}(t_i)$ are the entries ofy_pred
, and$t_i$ arey_pred.index
.
update(self, y, X=None, update_params=True):
-
y
:pd.Series
; this models the$y(t_i)$ and$t_i$ to which access is given inupdate
. The$y(t_i)$ are the entries ofy
, and$t_i$ arey.index
. -
X
:pd.DataFrame
; this models$x(t_i)$ and$x'(t_i)$ to which access is given inupdate
. The$x(t_i)$ and$x'(t_i)$ are the entries ofX
, with different components being the different variables ofX
. The$t_i$ areX.index
. -
update_params
:Boolean
; this is a switch for the behaviour ofupdate
. IfTrue
, models default behaviour. IfFalse
, overrides the behaviour to prevent updating of model parameters.
Behaviour if update_params=True
:
- retrieves then updates model representation, writes updates representation to any number of private variables representing the model to
self
. - sets the cut-off to the largest of the
$t_i$ passed iny
, i.e., the largest element ofy.index
- should have no side effects on arguments
Behaviour if update_params=False
:
- sets the cut-off to the largest of the
$t_i$ passed iny
, i.e., the largest element ofy.index
- should have no side effects on arguments
- may change model representation (e.g., through storing
y
andX
internally), but should not have an effect on subsequent calls ofpredict
untilupdate
is called with argumentupdate_params=True
Returns: self
get_params, set_params
This should implement parameter access and follow the sklearn
specifications verbatim.
todo: add update_predict
, score
, get_fitted_params
Forecasters should inherit from:
-
sklearn
'sBaseEstimator
which provides hyper-parameter interface and estimator composition functionality -
sktime
'sBaseForecaster
which provides scitype specific template functionality
talk about type checks here
todo: return_pred_int
and alpha
for predict
update
update_predict
update_predict_single