Explore Library
Code QuizIntermediate

Pipeline and ColumnTransformer Basics

Spot the mistake when applying a fitted preprocessing pipeline to test data.

Codepython
from sklearn.pipeline import Pipeline
from sklearn.compose import ColumnTransformer
from sklearn.preprocessing import StandardScaler, OneHotEncoder

pre = ColumnTransformer([
    ('num', StandardScaler(), ['age', 'income']),
    ('cat', OneHotEncoder(), ['city'])
])

pipe = Pipeline([('pre', pre)])

X_train_t = pipe.fit_transform(X_train)
X_test_t = pipe.fit_transform(X_test)

What is the bug in this preprocessing code?