Skip to content

TransformedTargetForecaster

TransformedTargetForecaster

class TransformedTargetForecaster(steps)[source]

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] and tp[i] are transformers (t to pre-, tp to post-process), and f is an sktime forecaster, the pipeline behaves as follows:

fit(y, X, fh) - changes state by running t1.fit_transform

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

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

then running tN.inverse_transform with X= the output of f, y=X, then t2.inverse_transform on X= the output of t1.inverse_transform, etc, sequentially, with t[i-1] receiving the output of t[i] as X, then running tp1.transform with X= the output of t1, y=X, then tp2.transform on X= the output of tp1.transform, etc, sequentially, with tp[i] receiving the output of tp[i-1]. The output of tpM is returned, or of t1.inverse_transform if M=0.

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)

TransformedTargetForecaster 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, my_tp inherit from BaseTransformer, then, for instance, my_t1 * my_t2 * my_forecaster * my_tp will result in the same object as obtained from the constructor TransformedTargetForecaster([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.

Parameters:
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.

Attributes:
steps_list of tuples (str, estimator) of sktime transformers or forecasters

clones of estimators in steps which are fitted in the pipeline is always in (str, estimator) format, even if steps is just a list strings not passed in steps are replaced by unique generated strings i-th transformer in steps_ is clone of i-th in steps

forecaster_estimator, reference to the unique forecaster in steps_

Return reference to the forecaster in the pipeline.

transformers_pre_list of tuples (str, transformer) of sktime transformers

Return reference to the list of pre-forecast transformers.

transformers_post_list of tuples (str, transformer) of sktime transformers

Return reference to the list of post-forecast transformers.

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()

Methods

check_is_fitted([method_name])

Check if the estimator has been fitted.

clone()

Obtain a clone of the object with same hyper-parameters and config.

clone_tags(estimator[, tag_names])

Clone tags from another object as dynamic override.

create_test_instance([parameter_set])

Construct an instance of the class, using first test parameter set.

create_test_instances_and_names([parameter_set])

Create list of all test instances and a list of names for them.

fit(y[, X, fh])

Fit forecaster to training data.

fit_predict(y[, X, fh, X_pred])

Fit and forecast time series at future horizon.

get_class_tag(tag_name[, tag_value_default])

Get class tag value from class, with tag level inheritance from parents.

get_class_tags()

Get class tags from class, with tag level inheritance from parent classes.

get_config()

Get config flags for self.

get_fitted_params([deep])

Get fitted parameters.

get_param_defaults()

Get object's parameter defaults.

get_param_names([sort])

Get object's parameter names.

get_params([deep])

Get parameters of estimator.

get_pretrained_params([deep])

Get pretrained parameters of this estimator.

get_tag(tag_name[, tag_value_default, ...])

Get tag value from instance, with tag level inheritance and overrides.

get_tags()

Get tags from instance, with tag level inheritance and overrides.

get_test_params([parameter_set])

Return testing parameter settings for the estimator.

inverse_transform(Z[, X])

Reverse transformation on input series Z.

is_composite()

Check if the object is composite.

load_from_path(serial)

Load object from file location.

load_from_serial(serial)

Load object from serialized memory container.

predict([fh, X])

Forecast time series at future horizon.

predict_interval([fh, X, coverage])

Compute/return prediction interval forecasts.

predict_proba([fh, X, marginal])

Compute/return fully probabilistic forecasts.

predict_quantiles([fh, X, alpha])

Compute/return quantile forecasts.

predict_residuals([y, X])

Return residuals of time series forecasts.

predict_var([fh, X, cov])

Compute/return variance forecasts.

pretrain(y[, X, fh])

Pre-train forecaster on panel (global) data.

reset()

Reset the object to a clean post-init state.

save([path, serialization_format])

Save serialized self to bytes-like object or to (.zip) file.

score(y[, X, fh])

Scores forecast against ground truth, using MAPE (non-symmetric).

set_config(**config_dict)

Set config flags to given values.

set_params(**kwargs)

Set the parameters of estimator.

set_random_state([random_state, deep, ...])

Set random_state pseudo-random seed parameters for self.

set_tags(**tag_dict)

Set instance level tag overrides to given values.

transform(Z[, X])

Return transformed version of input series Z.

update(y[, X, update_params])

Update cutoff value and, optionally, fitted parameters.

update_predict(y[, cv, X, update_params, ...])

Make predictions and update model iteratively over the test set.

update_predict_single([y, fh, X, update_params])

Update model with new data and make forecasts.