Back to models
Transformer

CombineTransformers

Combination operation applied to the outputs of multiple transformers.

Applies op to the value result of multiple transformers, obtaining op(output1, output2, ...), where outputi is the output of transformer i coerced to a numpy.ndarray.

If op is a numpy ufunc, the operation is applied elementwise.

This transformer applies a user-supplied combination operation (such as addition, subtraction, multiplication, division, or any custom function) to the outputs of two or more transformers. The operation is performed across all outputs, and the result is returned as a single DataFrame or Series.

All transformers must produce outputs with matching indexes and columns. If the indexes or columns do not match, a ValueError is raised. The operation must accept as many arguments as there are transformers, and should return a DataFrame or Series.

Quickstart

python
from sktime.transformations.compose import CombineTransformers

estimator = CombineTransformers(transformers, op)

Parameters(2)

transformerslist of (str, transformer) tuples
List of transformers to apply to the input data. Each tuple contains a name and a transformer instance. All transformers must inherit from BaseTransformer.
opnumpy ufuncs or callable of same signature
Function to apply to the outputs of the transformers. Should accept N arrays/Series/DataFrames and return a DataFrame or Series. Examples include numpy ufuncs (e.g., np.add, np.divide) or custom functions.

Examples

>>> import numpy as np
>>> from sktime.utils._testing.series import _make_series
>>> from sktime.transformations.exponent import ExponentTransformer
>>> from sktime.transformations.compose import CombineTransformers
>>> transformers = [
... ("t1", ExponentTransformer (power = 2)),
... ("t2", ExponentTransformer (power = 1)),
... ]
>>> op = CombineTransformers (transformers, op = np. divide)
>>> X = _make_series (n_timepoints = 10, n_columns = 2, random_state = 42)
>>> Xt = op. fit_transform (X)
>>> # Xt contains the elementwise ratio of squared to original values

References

  1. Inspired by scikit-learn’s FunctionTransformer and FeatureUnion.