ColumnEnsembleTransformer
ColumnEnsembleTransformer
- class ColumnEnsembleTransformer(transformers, remainder=None, feature_names_out='auto')[source]
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
FeatureUnionwithColumnSelect, but can be more convenient or compact.- Parameters:
- 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
- Attributes:
- transformers_list
The collection of fitted transformations as tuples of (name, fitted_transformer, column).
fitted_transformercan be an estimator, “drop”, or “passthrough”. In case there were no columns selected, this will be the unfitted transformer. If there are remaining columns, the final element is a tuple of the form: (“remainder”, transformer, remaining_columns) corresponding to theremainderparameter. If there are remaining columns, thenlen(transformers_)==len(transformations)+1, otherwiselen(transformers_)==len(transformations).
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)
Methods
check_is_fitted([method_name])Check if the estimator has been fitted.
clone()Obtain a clone of the object with same hyper-parameters and config.
clone_tags(estimator[, tag_names])Clone tags from another object as dynamic override.
create_test_instance([parameter_set])Construct an instance of the class, using first test parameter set.
create_test_instances_and_names([parameter_set])Create list of all test instances and a list of names for them.
fit(X[, y])Fit transformer to X, optionally to y.
fit_transform(X[, y])Fit to data, then transform it.
get_class_tag(tag_name[, tag_value_default])Get class tag value from class, with tag level inheritance from parents.
get_class_tags()Get class tags from class, with tag level inheritance from parent classes.
get_config()Get config flags for self.
get_fitted_params([deep])Get fitted parameters.
get_param_defaults()Get object's parameter defaults.
get_param_names([sort])Get object's parameter names.
get_params([deep])Get parameters of estimator.
get_tag(tag_name[, tag_value_default, ...])Get tag value from instance, with tag level inheritance and overrides.
get_tags()Get tags from instance, with tag level inheritance and overrides.
get_test_params()Return testing parameter settings for the estimator.
inverse_transform(X[, y])Inverse transform X and return an inverse transformed version.
is_composite()Check if the object is composite.
load_from_path(serial)Load object from file location.
load_from_serial(serial)Load object from serialized memory container.
reset()Reset the object to a clean post-init state.
save([path, serialization_format])Save serialized self to bytes-like object or to (.zip) file.
set_config(**config_dict)Set config flags to given values.
set_params(**kwargs)Set the parameters of estimator.
set_random_state([random_state, deep, ...])Set random_state pseudo-random seed parameters for self.
set_tags(**tag_dict)Set instance level tag overrides to given values.
transform(X[, y])Transform X and return a transformed version.
update(X[, y, update_params])Update transformer with X, optionally y.

