Python 我犯了这个错误';数据的DataFrame.d类型必须是int、float、bool或category';

Python 我犯了这个错误';数据的DataFrame.d类型必须是int、float、bool或category';,python,xgboost,Python,Xgboost,我将把它训练成xgboost模型 “开始时间”、“结束时间”列采用yyyy-mm-dd hh:mm:ss格式 我使用astype(str)将其更改为string,并使用正则表达式将其更改为yyyymmddhhmmss格式 xgb_model = xgboost.XGBClassifier(eta=0.1, nrounds=1000, max_depth=8, colsample_bytree=0.5, scale_pos_weight=1.1, booster='gbtree',

我将把它训练成xgboost模型

“开始时间”、“结束时间”列采用yyyy-mm-dd hh:mm:ss格式

我使用astype(str)将其更改为string,并使用正则表达式将其更改为yyyymmddhhmmss格式

xgb_model = xgboost.XGBClassifier(eta=0.1, nrounds=1000, max_depth=8, colsample_bytree=0.5, scale_pos_weight=1.1, booster='gbtree', 
                                  metric='multi:softmax')
hr_pred = xgb_model.fit(x_train, np.ravel(y_train, order='C')).predict(x_test)
print(classification_report(y_test, hr_pred))
但是这种错误发生了,我以前从未见过这样的情况

我怎样才能解决这个问题


谢谢您的帮助。

您似乎有分类数据。开始时间和结束时间是对象类型

您需要删除它们或对它们进行编码

放下它们

xgb\u model=xgboost.XGBClassifier(eta=0.1,nrounds=1000,最大深度=8,colsample\u bytree=0.5,scale\u pos\u weight=1.1,booster='gbtree',
metric='multi:softmax')
hr_pred=xgb_model.fit(x_train._get_numeric_data(),np.ravel(y_train,order='C'))。predict(x_test._get_numeric_data())
打印(分类报告(y检验、hr检验)

要对它们进行编码,请查看此库

Omg。成功了。非常感谢。非常感谢。如果您喜欢答案,请不要忘记投票并标记为已接受:)
ValueError: DataFrame.dtypes for data must be int, float, bool or categorical.  When
            categorical type is supplied, DMatrix parameter
            `enable_categorical` must be set to `True`.start_time, end_time