DocumentationClassesColumnTransformer

Class: ColumnTransformer

Applies transformers to columns of an array or 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.

Read more in the User Guide.

Python Reference

Constructors

new ColumnTransformer()

new ColumnTransformer(opts?): ColumnTransformer

Parameters

ParameterTypeDescription
opts?object-
opts.force_int_remainder_cols?booleanForce the columns of the last entry of transformers_, which corresponds to the ā€œremainderā€ transformer, to always be stored as indices (int) rather than column names (str). See description of the transformers_ attribute for details.
opts.n_jobs?numberNumber of jobs to run in parallel. undefined means 1 unless in a joblib.parallel_backend context. \-1 means using all processors. See Glossary for more details.
opts.remainder?"drop" | "passthrough"By default, only the specified columns in transformers 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 transformers, but present in the data passed to fit will be automatically passed through. This subset of columns is concatenated with the output of the transformers. For dataframes, extra columns not seen during fit will be excluded from the output of transform. By setting remainder to be an estimator, the remaining non-specified columns will use the remainder estimator. The estimator must support fit and transform. Note that using this feature requires that the DataFrame columns input at fit and transform have identical order.
opts.sparse_threshold?numberIf the output of the different transformers contains sparse matrices, these will be stacked as a sparse matrix if the overall density is lower than this value. Use sparse_threshold=0 to always return dense. When the transformed output consists of all dense data, the stacked result will be dense, and this keyword will be ignored.
opts.transformer_weights?anyMultiplicative weights for features per transformer. The output of the transformer is multiplied by these weights. Keys are transformer names, values the weights.
opts.transformers?anyList of (name, transformer, columns) tuples specifying the transformer objects to be applied to subsets of the data.
opts.verbose?booleanIf true, the time elapsed while fitting each transformer will be printed as it is completed.
opts.verbose_feature_names_out?booleanIf true, ColumnTransformer.get_feature_names_out will prefix all feature names with the name of the transformer that generated that feature. If false, ColumnTransformer.get_feature_names_out will not prefix any feature names and will error if feature names are not unique.

Returns ColumnTransformer

Defined in generated/compose/ColumnTransformer.ts:25

Properties

PropertyTypeDefault valueDefined in
_isDisposedbooleanfalsegenerated/compose/ColumnTransformer.ts:23
_isInitializedbooleanfalsegenerated/compose/ColumnTransformer.ts:22
_pyPythonBridgeundefinedgenerated/compose/ColumnTransformer.ts:21
idstringundefinedgenerated/compose/ColumnTransformer.ts:18
optsanyundefinedgenerated/compose/ColumnTransformer.ts:19

Accessors

feature_names_in_

Get Signature

get feature_names_in_(): Promise<ArrayLike>

Names of features seen during fit. Defined only when X has feature names that are all strings.

Returns Promise<ArrayLike>

Defined in generated/compose/ColumnTransformer.ts:504


n_features_in_

Get Signature

get n_features_in_(): Promise<number>

Number of features seen during fit. Only defined if the underlying transformers expose such an attribute when fit.

Returns Promise<number>

Defined in generated/compose/ColumnTransformer.ts:477


output_indices_

Get Signature

get output_indices_(): Promise<any>

A dictionary from each transformer name to a slice, where the slice corresponds to indices in the transformed output. This is useful to inspect which transformer is responsible for which transformed feature(s).

Returns Promise<any>

Defined in generated/compose/ColumnTransformer.ts:450


py

Get Signature

get py(): PythonBridge

Returns PythonBridge

Set Signature

set py(pythonBridge): void

Parameters

ParameterType
pythonBridgePythonBridge

Returns void

Defined in generated/compose/ColumnTransformer.ts:80


sparse_output_

Get Signature

get sparse_output_(): Promise<boolean>

Boolean flag indicating whether the output of transform is a sparse matrix or a dense numpy array, which depends on the output of the individual transformers and the sparse_threshold keyword.

Returns Promise<boolean>

Defined in generated/compose/ColumnTransformer.ts:423


transformers_

Get Signature

get transformers_(): Promise<any[]>

The collection of fitted transformers as tuples of (name, fitted_transformer, column). fitted_transformer can be an estimator, or 'drop'; 'passthrough' is replaced with an equivalent FunctionTransformer. 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 the remainder parameter. If there are remaining columns, then len(transformers_)==len(transformers)+1, otherwise len(transformers_)==len(transformers).

Returns Promise<any[]>

Defined in generated/compose/ColumnTransformer.ts:396

Methods

dispose()

dispose(): Promise<void>

Disposes of the underlying Python resources.

Once dispose() is called, the instance is no longer usable.

Returns Promise<void>

Defined in generated/compose/ColumnTransformer.ts:134


fit()

fit(opts): Promise<any>

Fit all transformers using X.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters to be passed to the underlying transformersā€™ fit and transform methods. You can only pass this if metadata routing is enabled, which you can enable using sklearn.set_config(enable_metadata_routing=true).
opts.X?ArrayLike[]Input data, of which specified subsets are used to fit the transformers.
opts.y?ArrayLike[]Targets for supervised learning.

Returns Promise<any>

Defined in generated/compose/ColumnTransformer.ts:151


fit_transform()

fit_transform(opts): Promise<ArrayLike>

Fit all transformers, transform the data and concatenate results.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters to be passed to the underlying transformersā€™ fit and transform methods. You can only pass this if metadata routing is enabled, which you can enable using sklearn.set_config(enable_metadata_routing=true).
opts.X?ArrayLike[]Input data, of which specified subsets are used to fit the transformers.
opts.y?ArrayLikeTargets for supervised learning.

Returns Promise<ArrayLike>

Defined in generated/compose/ColumnTransformer.ts:197


get_feature_names_out()

get_feature_names_out(opts): Promise<any>

Get output feature names for transformation.

Parameters

ParameterTypeDescription
optsobject-
opts.input_features?anyInput features.

Returns Promise<any>

Defined in generated/compose/ColumnTransformer.ts:245


get_metadata_routing()

get_metadata_routing(opts): Promise<any>

Get metadata routing of this object.

Please check User Guide on how the routing mechanism works.

Parameters

ParameterTypeDescription
optsobject-
opts.routing?anyA MetadataRouter encapsulating routing information.

Returns Promise<any>

Defined in generated/compose/ColumnTransformer.ts:283


init()

init(py): Promise<void>

Initializes the underlying Python resources.

This instance is not usable until the Promise returned by init() resolves.

Parameters

ParameterType
pyPythonBridge

Returns Promise<void>

Defined in generated/compose/ColumnTransformer.ts:93


set_output()

set_output(opts): Promise<any>

Set the output container when "transform" and "fit_transform" are called.

Calling set_output will set the output of all estimators in transformers and transformers_.

Parameters

ParameterTypeDescription
optsobject-
opts.transform?"default" | "pandas" | "polars"Configure output of transform and fit_transform.

Returns Promise<any>

Defined in generated/compose/ColumnTransformer.ts:321


transform()

transform(opts): Promise<ArrayLike>

Transform X separately by each transformer, concatenate results.

Parameters

ParameterTypeDescription
optsobject-
opts.params?anyParameters to be passed to the underlying transformersā€™ transform method. You can only pass this if metadata routing is enabled, which you can enable using sklearn.set_config(enable_metadata_routing=true).
opts.X?ArrayLike[]The data to be transformed by subset.

Returns Promise<ArrayLike>

Defined in generated/compose/ColumnTransformer.ts:355