I am having the following error when trying to fit a pipeline that uses a XGBoost classifier as its final steps:
DataFrame.dtypes for data must be int, float or bool. Did not expect the data types in fields [Categorical Columns here].
I am using the following pipeline, with a TargetEncoder to encode the categorical columns:
numerical_transformer = MinMaxScaler()
categorical_transformer = TargetEncoder()
numerical_cols = X.select_dtypes(include=['float', 'int']).columns
categorical_cols = X.select_dtypes(include='object').columns
preprocessor = make_column_transformer(
(categorical_transformer, categorical_cols),
(numerical_transformer, numerical_cols),
remainder='passthrough')
clf = XGBClassifier(objective= 'binary:logistic')
pipe = make_pipeline(preprocessor, clf)
pipe.fit(X_train,y_train)
The problem is that, apparently, the TargetEncoder sets object to the data types of the encoded categorical columns. An so, XGBoost throws the error.
So, how could I set the data type to, for example, float before it is used by the XGBClassifier object?