TransformedTargetForecaster
Meta-estimator for forecasting transformed time series.
Pipeline functionality to apply transformers to endogeneous time series, y. The exogenous data, X, is not transformed. To transform X, the ForecastingPipeline can be used.
- For a list
t1,t2, …,tN,f,tp1,tp2, …,tpM, where
t[i]andtp[i]are transformers (tto pre-,tpto post-process), andfis an sktime forecaster, the pipeline behaves as follows:fit(y, X, fh)- changes state by runningt1.fit_transformwith
X=y,y=X, thent2.fit_transformonX=the output oft1.fit_transform,y=X, etc, sequentially, witht[i]receiving the output oft[i-1]asX, then runningf.fitwithybeing the output oft[N], andX=X, then runningtp1.fit_transformwithX=y,y=X, thentp2.fit_transformonX=the output oftp1.fit_transform, etc sequentially, withtp[i]receiving the output oftp[i-1],predict(X, fh)- result is of executingf.predict, withX=X,fh=fh,then running
tN.inverse_transformwithX=the output off,y=X, thent2.inverse_transformonX=the output oft1.inverse_transform, etc, sequentially, witht[i-1]receiving the output oft[i]asX, then runningtp1.transformwithX=the output oft1,y=X, thentp2.transformonX=the output oftp1.transform, etc, sequentially, withtp[i]receiving the output oftp[i-1]. The output oftpMis returned, or oft1.inverse_transformifM=0.predict_interval(X, fh),predict_quantiles(X, fh)- aspredict(X, fh),with
predict_intervalorpredict_quantilessubstituted forpredictpredict_var,predict_proba- uses base class default to obtaincrude 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)
TransformedTargetForecastercan also be created by using the magicmultiplication on any forecaster, i.e., if
my_forecasterinherits fromBaseForecaster, andmy_t1,my_t2,my_tpinherit fromBaseTransformer, then, for instance,my_t1 * my_t2 * my_forecaster * my_tpwill result in the same object as obtained from the constructorTransformedTargetForecaster([my_t1, my_t2, my_forecaster, my_tp]). Magic multiplication can also be used with (str, transformer) pairs, as long as one element in the chain is a transformer.
Quickstart
from sktime.forecasting.compose import TransformedTargetForecaster
estimator = TransformedTargetForecaster(steps)Parameters(1)
- stepslist of sktime transformers and forecasters, or
list of tuples (str, estimator) of
sktimetransformers or forecasters. The list must contain exactly one forecaster. These are “blueprint” transformers resp forecasters, forecaster/transformer states do not change whenfitis called.
Examples
>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.forecasting.compose import TransformedTargetForecaster
>>> from sktime.transformations.impute import Imputer
>>> from sktime.transformations.detrend import Detrender
>>> from sktime.transformations.exponent import ExponentTransformer
>>> y = load_airline () Example 1: string/estimator pairs
>>> pipe = TransformedTargetForecaster (steps = [
... ("imputer", Imputer (method = "mean")),
... ("detrender", Detrender ()),
... ("forecaster", NaiveForecaster (strategy = "drift")),
... ])
>>> pipe. fit (y) TransformedTargetForecaster(
... )
>>> y_pred = pipe. predict (fh = [1, 2, 3 ]) Example 2: without strings
>>> pipe = TransformedTargetForecaster ([
... Imputer (method = "mean"),
... Detrender (),
... NaiveForecaster (strategy = "drift"),
... ExponentTransformer (),
... ]) Example 3: using the dunder method
>>> forecaster = NaiveForecaster (strategy = "drift")
>>> imputer = Imputer (method = "mean")
>>> pipe = imputer * Detrender () * forecaster * ExponentTransformer ()