ColumnEnsembleTransformer
Column-wise application of transformers.
Quickstart
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
transformationsare transformed and combined in the output, and the non-specified columns are dropped. (default of"drop"). By specifyingremainder="passthrough", all remaining columns that were not specified intransformationswill be automatically passed through. This subset of columns is concatenated with the output of the transformations. By settingremainderto be an estimator, the remaining non-specified columns will use theremainderestimator. The estimator must supportfitandtransform.- 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)