scikit-learn Transformers

tsfresh includes three scikit-learn compatible transformers. You can easily add them to your existing data science pipeline. If you are not familiar with scikit-learns pipeline we recommend you take a look at the official documentation[1].

The purpose of such a pipeline is to assemble several preprocessing steps that can be cross-validated together while setting different parameters. Our tsfresh transformer allows you to extract and filter the time series features during such a preprocessing sequence.

The first two estimators contained in tsfresh are theFeatureAugmenter, which extracts the features, and theFeatureSelector, which only performs the feature selection algorithm. It is preferable to combine extracting and filtering of the features in a single step to avoid unnecessary feature calculations. Hence, we have theRelevantFeatureAugmenter, which combines both the extraction and filtering of the features in a single step.

In the following example you see how we combine tsfreshsRelevantFeatureAugmenterand aRandomForestClassifierinto a single pipeline. This pipeline can then fit both our transformer and the classifier in one step.

The parameters of the augment transformer correspond to the parameters of the top-level convenience functionextract_relevant_features(). In the example, we only set the names of two columnscolumn_id=id,column_sort=time(seeData Formatsfor an explanation of those parameters).

Because we cannot pass the time series container directly as a parameter to the augmenter step when calling fit or transform on asklearn.pipeline.Pipelinewe have to set it manually by callingpipeline.set_params(augmenter__timeseries_container=df_ts). In general, you can change the time series container from which the features are extracted by calling either the pipelinesset_params()method or the transformersset_timeseries_container()method.

For further examples, see the Jupyter Notebook pipeline_example.ipynb in the notebooks folder of the tsfresh package.