I am trying to perform OneHotEncoding as well as feature scaling on my training and testing data separately, steps I did:
X = df.drop("target", axis = 1)
y = df.target
X_train,X_test,y_train,y_test = train_test_split(X, y, test_size=0.2)
categorial_features = [List of Categorical Features]
numerical_features = [List of Numerical Features]
one_hot = OneHotEncoder()
scaler = StandardScaler()
tranformer = ColumnTransformer([("one_hot", one_hot, categorial_features),("standard_scaler", scaler, numerical_features)], remainder = "passthrough")
transformed_X_train = tranformer.fit_transform(X_train)
transformed_X_test = tranformer.fit_transform(X_test)
But now the shapes of transformed_X_train
, and transformed_X_test
are different, I know the reason why it is different, but I want to know how to deal with this situation?
Thank you.