What does ColumnTransformer do and when do you need it?
easyAnswer
- Applies different transformers to different subsets of columns in the same DataFrame and stitches the outputs back together into a single feature matrix.
- Standard use: one-hot encode categoricals, standardize numerics, drop or passthrough others — all in one step, fit inside a Pipeline.
- Combined with you can select columns by dtype or name pattern instead of hard-coding indices.
- The idiomatic way to handle mixed tabular data in scikit-learn.
Check yourself — multiple choice
- It only works on numeric features
- Applies different transformers to different column subsets; combines outputs into one matrix
- It's a wrapper around KMeans
- It replaces cross-validation
ColumnTransformer: apply different preprocessing per column subset; standard mixed-type handling.
#pipelines#preprocessing
Practise Supervised Learning
215 interview questions in this topic.
Related questions
- You did StandardScaler().fit_transform(X) then split into train/test. Why is this wrong?
- Which models need feature scaling and which don't?
- Why must you standardize features before applying L1 or L2 regularization?
- Your scikit-learn logistic regression warns 'lbfgs failed to converge'. What do you do?
- Why is feature scaling critical for SVMs?
- StandardScaler vs MinMaxScaler vs RobustScaler — how do you choose?