Back to models
Transformer

YtoX

Create exogenous features which are a copy of the endogenous data.

Quickstart

python
from sktime.transformations.compose import YtoX

estimator = YtoX(subset_index=False)

Parameters(1)

subset_indexboolean, optional, default=False

if True, subsets the output of transform to X.index, i.e., outputs y.loc[X.index]

Examples

Use case: creating exogenous data from index, if no exogenous data is available.
>>> from sktime.datasets import load_airline
>>> from sktime.transformations.compose import YtoX
>>> from sktime.transformations.fourier import FourierFeatures
>>> from sktime.forecasting.arima import ARIMA
>>> from sktime.forecasting.compose import ForecastingPipeline
>>> 
>>> # data with no exogenous features
>>> y = load_airline ()
>>> 
>>> # create a pipeline with Fourier features and ARIMA
>>> pipe = ForecastingPipeline (
... [
... YtoX (),
... FourierFeatures (sp_list = [24, 24 * 7 ], fourier_terms_list = [10, 5 ]),
... ARIMA (order = (1, 1, 1))
... ]
... )
>>> 
>>> # fit and forecast, using Fourier features as exogenous data
>>> pred = pipe. fit_predict (y, fh = [1, 2, 3, 4, 5 ]) Use case: using lagged endogenous variables as exogenous data.
>>> from sktime.datasets import load_airline
>>> from sktime.transformations.compose import YtoX
>>> from sktime.transformations.lag import Lag
>>> from sktime.transformations.impute import Imputer
>>> from sktime.forecasting.sarimax import SARIMAX
>>> 
>>> # data with no exogenous features
>>> y = load_airline ()
>>> 
>>> # create the pipeline
>>> lagged_y_trafo = YtoX () * Lag (1, index_out = "original") * Imputer ()
>>> 
>>> # we need to specify index_out="original" as otherwise ARIMA gets 1 and 2 ahead
>>> # use lagged_y_trafo to generate X
>>> forecaster = lagged_y_trafo ** SARIMAX ()
>>> 
>>> # fit and forecast next value, with lagged y as exogenous data
>>> forecaster. fit (y, fh = [1 ])
>>> y_pred = forecaster. predict () Use case: using summarized endogenous variables as exogenous data.
>>> from sktime.datasets import load_airline
>>> from sktime.transformations.summarize import WindowSummarizer
>>> from sktime.transformations.compose import YtoX
>>> from sktime.forecasting.compose import make_reduction
>>> from sktime.forecasting.compose import ForecastingPipeline
>>> from sklearn.ensemble import GradientBoostingRegressor
>>> 
>>> # data with no exogenous features
>>> y = load_airline ()
>>> 
>>> # keyword arguments for WindowSummarizer
>>> kwargs = {
... "lag_feature": {
... "lag": [1 ],
... "mean": [[1, 3 ], [3, 6 ]],
... "std": [[1, 4 ]],
... },
... "truncate": 'bfill',
... }
>>> 
>>> # create forecaster from sklearn regressor using make_reduction
>>> forecaster = make_reduction (
... GradientBoostingRegressor (),
... strategy = "recursive",
... pooling = "global",
... window_length = 12,
... )
>>> 
>>> # create the pipeline
>>> pipe = ForecastingPipeline (
... steps = [
... ("ytox", YtoX ()),
... ("summarizer", WindowSummarizer (** kwargs)),
... ("forecaster", forecaster),
... ]
... )
>>> 
>>> # fit and forecast, with summarized y as exogenous data
>>> preds = pipe. fit_predict (y = y, fh = range (1, 20))