I am trying to implement a model that uses ColumnTransformer() followed by SVC().
My transform method looks like:
num_features = X_train_svm.select_dtypes(include=np.number).columns.to_list()
cat_features = X_train_svm.select_dtypes(include=['object']).columns.to_list()
transform1 = make_column_transformer([(StandardScaler(), num_features),
(OneHotEncoder(), cat_features)
])
Followed by a pipeline:
pipe = make_pipeline(transform1, svm.SVC())
Then when i try to fit train and test data :
pipe.fit(X_train, y_train)
I get the error :: TypeError: All estimators should implement fit and transform, or can be 'drop' or 'passthrough' specifiers. '(StandardScaler(), ['Height', 'Age', 'Weight', 'Quantity', 'Cost'])' (type <class 'tuple'>) doesn't.
Please help me fix this error.
I tried changing scaler to Ordinal Scaler, tried reshaping the data using (-1,1), but nothing worked.
The transformers given to
make_column_transformer
shouldn't be contained in a list: they are separate positional arguments. See the example in the docs.In your example, just delete the square brackets in the definition of
transform1
.