Pipeline
Implementation of a Graphpipeline.
This class is a generalized graph pipeline. Generalized means that it can contain forecasters, classifiers, etc. The graph pipeline mean that the structure is not linear. I.e., the each element of the pipeline can be the input of multiple other steps and not only one successors.
fit(y, X, *args)- changes state by runningfiton all sktime estimators andtransformers in the pipeline. Note that depending on the sktime estimators and transformers that are added to the pipeline, different keywords are required. E.g., if a forecaster is part of the pipeline, a forecast horizon (fh) should be provided.
predict(X, *args)- Results in calling predict on the estimators in the pipelineand transform or the specified method on the other skobjects in the pipeline. Depending on the skobject added to the pipeline, you might need to pass additional parameters to predict.
predict_interval(X, fh),predict_quantiles(X, fh)- aspredict(X, fh),with
predict_intervalorpredict_quantilessubstituted forpredict.
predict_var, predict_proba - are currently not supported get_params, set_params uses sklearn compatible nesting interface add_step(skobject, name, edges, method, **kwargs) - adds a skobject to the
pipeline and setting the name as identifier and the steps specified with edges as input steps (predecessors). Thereby the method that should be called can be overridden using the method kwarg. Further provided kwargs are directly provided to the skobject if it is called.
Quickstart
from sktime.pipeline.pipeline import Pipeline
estimator = Pipeline(steps=None)Parameters(1)
- param stepsA list of dicts that specify the steps of the pipeline. Further
steps can be added by using add_step method. The dict requires the following keys:
- skobject:
sktimeobject, the skobject that should be added to the pipeline
- skobject:
Examples
>>> from sktime.classification.distance_based import KNeighborsTimeSeriesClassifier >>> from sktime.datasets import load_arrow_head, load_longley >>> from sktime.split import temporal_train_test_split >>> from sktime.forecasting.naive import NaiveForecaster >>> from sktime.pipeline import Pipeline >>> from sktime.transformations.compose import Id >>> from sktime.transformations.boxcox import BoxCoxTransformer >>> from sktime.transformations.exponent import ExponentTransformer Example 1: Simple sequential pipeline of transformers using the generalized non-sequential pipeline implementation >>> y, X = load_longley () >>> general_pipeline = Pipeline () >>> for step in [ ... { "skobject": ExponentTransformer (), "name": "exp", "edges": { "X": "X" }}, ... { "skobject": BoxCoxTransformer (), "name": "box", "edges": { "X": "exp" }}, ... ]: ... general_pipeline = general_pipeline. add_step (** step) >>> general_pipeline. fit (X = X) >>> result_general = general_pipeline. transform (X) Example 2: Classification sequential pipeline using the generalized non-sequential pipeline implementation >>> X, y = load_arrow_head (split = "train", return_X_y = True) >>> general_pipeline = Pipeline () >>> for step in [ ... { "skobject": ExponentTransformer (), "name": "exp", "edges": { "X": "X" }}, ... { "skobject": KNeighborsTimeSeriesClassifier (), ... "name": "knnclassifier", ... "edges": { "X": "exp", "y": "y" }}]: ... general_pipeline = general_pipeline. add_step (** step) >>> general_pipeline. fit (X = X, y = y) >>> result_general = general_pipeline. predict (X) Example 3: Forecasting pipeline with exogenous features using the generalized non-sequential pipeline implementation >>> y, X = load_longley () >>> y_train, y_test, X_train, X_test = temporal_train_test_split (y, X) >>> general_pipeline = Pipeline () >>> for step in [ ... { "skobject": ExponentTransformer (), "name": "exp", "edges": { "X": "X" }}, ... { "skobject": NaiveForecaster (), ... "name": "SARIMAX", ... "edges": { "X": "exp", "y": "y" }}]: ... general_pipeline = general_pipeline. add_step (** step) >>> general_pipeline. fit (y = y_train, X = X_train, fh = [1, 2, 3, 4 ]) >>> result_general = general_pipeline. predict (X = X_test) Acknowledgements This graphical pipeline is inspired by pyWATTS that is developed by the Institute for Automation and Applied Informatics (IAI) at Karlsruhe Institute of Technology. The implementation is supported by IAI and the author benHeid is funded by HelmholtzAI. Furthermore, we also want to credit @ViktorKaz for his independent pipeline design that is similar to this one.References
[1]@article{heidrich2021pywatts, title={pyWATTS: Python workflow automation tool for time series}, author={Heidrich, Benedikt and Bartschat, Andreas and Turowski, Marian and
Neumann, Oliver and Phipps, Kaleb and Meisenbacher, Stefan and Schmieder, Kai and Ludwig, Nicole and Mikut, Ralf and Hagenmeyer, Veit},
journal={arXiv preprint arXiv:2106.10157}, year={2021}
}