Zurück zu den Modellen
Forecaster

ForecastingPipeline

Pipeline for forecasting with exogenous data.

ForecastingPipeline is only applying the given transformers to X. The forecaster can also be a TransformedTargetForecaster containing transformers to transform y.

For a list t1, t2, …, tN, f

where t[i] are transformers, and f is an sktime forecaster, the pipeline behaves as follows:

fit(y, X, fh) changes state by running t1.fit_transform with X=X`, ``y=y

then t2.fit_transform on X= the output of t1.fit_transform, y=y, etc, sequentially, with t[i] receiving the output of t[i-1] as X, then running f.fit with X being the output of t[N], and y=y

predict(X, fh) - result is of executing f.predict, with fh=fh, and X

being the result of the following process: running t1.fit_transform with X=X, then t2.fit_transform on X= the output of t1.fit_transform, etc sequentially, with t[i] receiving the output of t[i-1] as X, and returning th output of tN to pass to f.predict as X.

predict_interval(X, fh), predict_quantiles(X, fh) - as predict(X, fh),

with predict_interval or predict_quantiles substituted for predict

predict_var, predict_proba - uses base class default to obtain

crude normal estimates from predict_quantiles.

get_params, set_params uses sklearn compatible nesting interface:

  • if list is unnamed, names are generated as names of classes

  • if names are non-unique, f"_{str(i)}" is appended to each name string where i is the total count of occurrence of a non-unique string inside the list of names leading up to it (inclusive)

ForecastingPipeline can also be created by using the magic multiplication

on any forecaster, i.e., if my_forecaster inherits from BaseForecaster, and my_t1, my_t2, inherit from BaseTransformer, then, for instance, my_t1 ** my_t2 ** my_forecaster will result in the same object as obtained from the constructor ForecastingPipeline([my_t1, my_t2, my_forecaster]). Magic multiplication can also be used with (str, transformer) pairs, as long as one element in the chain is a transformer.

Schnellstart

python
from sktime.forecasting.compose import ForecastingPipeline

estimator = ForecastingPipeline(steps)

Parameter(1)

stepslist of sktime transformers and forecasters, or

list of tuples (str, estimator) of sktime transformers or forecasters. The list must contain exactly one forecaster. These are “blueprint” transformers resp forecasters, forecaster/transformer states do not change when fit is called.

Beispiele

>>> from sktime.datasets import load_longley
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.forecasting.compose import ForecastingPipeline
>>> from sktime.transformations.impute import Imputer
>>> from sktime.forecasting.base import ForecastingHorizon
>>> from sktime.split import temporal_train_test_split
>>> from sklearn.preprocessing import MinMaxScaler
>>> y, X = load_longley ()
>>> y_train, _, X_train, X_test = temporal_train_test_split (y, X)
>>> fh = ForecastingHorizon (X_test. index, is_relative = False) Example 1: string/estimator pairs
>>> pipe = ForecastingPipeline (steps = [
... ("imputer", Imputer (method = "mean")),
... ("minmaxscaler", MinMaxScaler ()),
... ("forecaster", NaiveForecaster (strategy = "drift")),
... ])
>>> pipe. fit (y_train, X_train) ForecastingPipeline(
... )
>>> y_pred = pipe. predict (fh = fh, X = X_test) Example 2: without strings
>>> pipe = ForecastingPipeline ([
... Imputer (method = "mean"),
... MinMaxScaler (),
... NaiveForecaster (strategy = "drift"),
... ]) Example 3: using the dunder method Note: * (= apply to y) has precedence over ** (= apply to X)
>>> forecaster = NaiveForecaster (strategy = "drift")
>>> imputer = Imputer (method = "mean")
>>> pipe = (imputer * MinMaxScaler ()) ** forecaster Example 3b: using the dunder method, alternative
>>> pipe = imputer ** MinMaxScaler () ** forecaster