Back to models
Transformer

ColumnEnsembleTransformer

Column-wise application of transformers.

Applies transformations to columns of an array or pandas DataFrame. Simply takes the column transformer from sklearn and adds capability to handle pandas dataframe.

This estimator allows different columns or column subsets of the input to be transformed separately and the features generated by each transformer will be concatenated to form a single feature space. This is useful for heterogeneous or columnar data, to combine several feature extraction mechanisms or transformations into a single transformer.

Note: this estimator has the same effect as combining FeatureUnion with ColumnSelect, but can be more convenient or compact.

Quickstart

python
from sktime.transformations.compose import ColumnEnsembleTransformer

estimator = ColumnEnsembleTransformer(transformers, remainder=None, feature_names_out='auto')

Parameters(3)

transformerssktime trafo, or list of tuples (str, estimator, int or pd.index)

if tuples, with name = str, estimator is transformer, index as int or index if last element is index, it must be int, str, or pd.Index coercible if last element is int x, and is not in columns, is interpreted as x-th column all columns must be present in an index

If transformer, clones of transformer are applied to all columns. If list of tuples, transformer in tuple is applied to column with int/str index

remainder{“drop”, “passthrough”} or estimator, default “drop”

By default, only the specified columns in transformations are transformed and combined in the output, and the non-specified columns are dropped. (default of "drop"). By specifying remainder="passthrough", all remaining columns that were not specified in transformations will be automatically passed through. This subset of columns is concatenated with the output of the transformations. By setting remainder to be an estimator, the remaining non-specified columns will use the remainder estimator. The estimator must support fit and transform.

feature_names_outstr, one of “auto” (default), “flat”, “multiindex”, “original”

determines how return columns of return DataFrame-s are named has no effect if return mtype is one without column names “flat”: columns are flat, e.g., “transformername__variablename” “multiindex”: columns are MultiIndex, e.g., (transformername, variablename) “original: columns are as produced by transformers, e.g., variablename

if this results in non-unique index, ValueError exception is raised

“auto”: as “original” for any unique columns under “original”,

column names as “flat” otherwise

Examples

>>> import pandas as pd
>>> from sktime.transformations.compose import ColumnEnsembleTransformer
>>> from sktime.transformations.detrend import Detrender
>>> from sktime.transformations.difference import Differencer
>>> from sktime.datasets import load_longley Using integers (column iloc references) for indexing:
>>> y = load_longley ()[1 ][["GNP", "UNEMP" ]]
>>> transformer = ColumnEnsembleTransformer ([("difference", Differencer (), 1),
... ("trend", Detrender (), 0),
... ])
>>> y_transformed = transformer. fit_transform (y) Using strings for indexing:
>>> df = pd. DataFrame ({ "a": [1, 2, 3 ], "b": [4, 5, 6 ]})
>>> transformer = ColumnEnsembleTransformer (
... [("foo", Differencer (), "a"), ("bar", Detrender (), "b")]
... )
>>> transformed_df = transformer. fit_transform (df) Applying one transformer to multiple columns, multivariate:
>>> df = pd. DataFrame ({ "a": [1, 2, 3 ], "b": [4, 5, 6 ], "c": [7, 8, 9 ]})
>>> transformer = ColumnEnsembleTransformer (
... [("ab", Differencer (), ["a", 1 ]), ("c", Detrender (), 2)]
... )
>>> transformed_df = transformer. fit_transform (df)