I have four categorial features and a fifth numerical one (Var5). When I try the following code:
cat_attribs = ['var1','var2','var3','var4']
full_pipeline = ColumnTransformer([('cat', OneHotEncoder(handle_unknown = 'ignore'), cat_attribs)], remainder = 'passthrough')
X_train = full_pipeline.fit_transform(X_train)
model = XGBRegressor(n_estimators=10, max_depth=20, verbosity=2)
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
I get the following error message when the model tries to make its predictions:
ValueError: DataFrame.dtypes for data must be int, float, bool or categorical. When categorical type is supplied, DMatrix parameter
enable_categoricalmust be set toTrue.Var1, Var2, Var3, Var4
Does anyone know what's going wrong here?
In case it's helpful, here is a small sample of the X_train data and the y_train data:
Var1 Var2 Var3 Var4 Var5
1507856 JP 2009 6581 OME 325.787218
839624 FR 2018 5783 I_S 11.956326
1395729 BE 2015 6719 OME 42.888565
1971169 DK 2011 3506 RPP 70.094146
1140120 AT 2019 5474 NMM 270.082738
and:
Ind_Var
1507856 8.013558
839624 4.105559
1395729 7.830077
1971169 83.000000
1140120 51.710526