liveBook · Manning

ColumnTransformer

As explained in Ensemble Methods for Machine Learning

ColumnTransformer is a scikit-learn transformer that applies different transformations to specified subsets of input columns and combines their outputs.

ColumnTransformer routes different column groups through different preprocessing pipelines, then combines their outputs. A typical dataset sends continuous features through scaling and categorical features through encoding, so each type receives an appropriate transformation. section 8.1.4 section 8.3.2

A practical preprocessing workflow is:

  • Separate continuous and categorical column names. section 8.1.4
  • Build a pipeline for each group—for example, median imputation followed by StandardScaler for continuous data, and missing-value imputation followed by an encoder for categorical data. section 8.3.2
  • Pass those pipelines and their column lists to ColumnTransformer, optionally preserving unspecified columns with remainder='passthrough'. section 8.1.4
  • Fit the combined preprocessor on training data, then call transform on held-out data; do not fit preprocessing on the test set. section 8.1.4 section 8.3.2

Mixed-feature credit classification

For the Australian Credit Approval data, scaling continuous columns and one-hot encoding categorical columns expanded 14 input features to 38. A RandomForestClassifier reached 89.855% hold-out accuracy after transformation. section 8.1.4

from sklearn.compose import ColumnTransformer
ct = ColumnTransformer(
         transformers=[('continuous',                                #1
                            preprocess_continuous, cont_features),
                       ('categorical',                               #2
                            preprocess_categorical, cat_features)], 
                       remainder='passthrough')                      #3

Inspect a complete ColumnTransformer configuration assigning separate continuous and categorical pipelines, with passthrough for remaining columns. section 8.1.4

How Ensemble Methods for Machine Learning covers it

How deep it goes
Explains column routing, nested pipelines, fitting, transformation, passthrough, and leakage prevention, but not internal implementation.
Examples
Demonstrates mixed preprocessing on Australian Credit Approval and Adult income datasets, including feature expansion and classification evaluation.
What it assumes
Assumes familiarity with feature types, train-test splitting, preprocessing pipelines, and categorical encoders.
What you can do after
Operate/configure a ColumnTransformer that preprocesses training and test subsets consistently before classification.
How it connects
Connects ColumnTransformer with Pipeline, StandardScaler, SimpleImputer, OneHotEncoder, categorical encoding, and data leakage prevention.

Also explained in

Compare how 2 books explain ColumnTransformer →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Ensemble Methods for Machine Learning. The section links point to the parts of the book it draws on.