0
$\begingroup$

Here is the code to assign the variables

X = pd.DataFrame(np.c_[df['day'], df['spend'], df['platform'],df['month'],df['year']], columns=[['day', 'spend','platform','month','year']])
y = pd.DataFrame(np.c_[df['revenue']], columns=['revenue'])
train_X, test_X, train_y, test_y = train_test_split(X, y, test_size = 0.1, random_state = 123)

and following these lines of fitting the model

xgb_r = xg.XGBRegressor(objective ='reg:squarederror', booster='gbtree', n_estimators=350, max_depth=10, learning_rate=0.1)
xgb_r.fit(train_X, train_y)

I get the following error

DataFrame.dtypes for data must be int, float, bool or category. When categorical type is supplied, The experimental DMatrix parameter`enable_categorical` must be set to `True`.  Invalid columns:('day',): object, ('spend',): object, ('platform',): object, ('month',): object, ('year',): object

however when I check the datatype with

df.dtypes

I get the following

platform          int64
day               Int64
spend           float64
revenue        float64
year            int64
month           int64

Could anyone advise what the issue could be?

$\endgroup$

1 Answer 1

0
$\begingroup$

The columns consist of numpy objects, which themselves consist of int or float. Try switching from numpy objects to lists and then create a dataframe from the lists.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.