Back to models
Transformer

OptionalPassthrough

Wrap an existing transformer to tune whether to include it in a pipeline.

Quickstart

python
from sktime.transformations.compose import OptionalPassthrough

estimator = OptionalPassthrough(transformer, passthrough=False)

Parameters(2)

transformerEstimator

scikit-learn-like or sktime-like transformer to fit and apply to series. this is a “blueprint” transformer, state does not change when fit is called

passthroughbool, default=False
Whether to apply the given transformer or to just passthrough the data (identity transformation). If, True the transformer is not applied and the OptionalPassthrough uses the identity transformation.

Examples

>>> from sktime.datasets import load_airline
>>> from sktime.forecasting.naive import NaiveForecaster
>>> from sktime.transformations.compose import OptionalPassthrough
>>> from sktime.transformations.detrend import Deseasonalizer
>>> from sktime.transformations.adapt import TabularToSeriesAdaptor
>>> from sktime.forecasting.compose import TransformedTargetForecaster
>>> from sktime.forecasting.model_selection import ForecastingGridSearchCV
>>> from sktime.split import SlidingWindowSplitter
>>> from sklearn.preprocessing import StandardScaler
>>> # create pipeline
>>> pipe = TransformedTargetForecaster (steps = [
... ("deseasonalizer", OptionalPassthrough (Deseasonalizer ())),
... ("scaler", OptionalPassthrough (TabularToSeriesAdaptor (StandardScaler ()))),
... ("forecaster", NaiveForecaster ())])
>>> # putting it all together in a grid search
>>> cv = SlidingWindowSplitter (
... initial_window = 60,
... window_length = 24,
... start_with_window = True,
... step_length = 48)
>>> param_grid = {
... "deseasonalizer__passthrough": [True, False ],
... "scaler__transformer__transformer__with_mean": [True, False ],
... "scaler__passthrough": [True, False ],
... "forecaster__strategy": ["drift", "mean", "last" ]}
>>> gscv = ForecastingGridSearchCV (
... forecaster = pipe,
... param_grid = param_grid,
... cv = cv,
... n_jobs =- 1)
>>> gscv_fitted = gscv. fit (load_airline ())