如何解决获取错误,因为数据的 DataFrame.dtypes 必须是 int、float、bool 或 categorical
XGBOOST 中的完整错误是
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`.Year
数据是
<class 'pandas.core.frame.DataFrame'>
Int64Index: 50327 entries,0 to 50326
Data columns (total 4 columns):
# Column Non-Null Count Dtype
--- ------ -------------- -----
0 C_Id 50327 non-null int8
1 Year 50327 non-null datetime64[ns]
2 value 50327 non-null float64
3 R_Id 50327 non-null int8
dtypes: datetime64[ns](1),float64(1),int8(2)
memory usage: 2.3 MB
然后我做了,
t_date = "2019-01-01 00:00:00"
X_train = data[data["Year"]<t_date].drop(["value"],axis=1)
Y_train = data[data["Year"]<t_date]["value"]
X_test = data[data["Year"]>=t_date].drop(["value"],axis=1)
`
model = XGBRegressor(
max_depth = 8,n_estimators=1000,min_child_weight=300,colsample_bytree=0.8,subsample=0.8,eta=0.3,seed=42)
model.fit(X_train,Y_train,eval_metric="rmse",eval_set=[(X_train,Y_train)],verbose =True,early_stopping_rounds=10)
我哪里出错了,如果您需要什么,请询问 感谢您的帮助!
编辑: 我将 Year 类型转换为字符串,然后转换为 int
结果是这样的,
[461] validation_0-rmse:8791.25293
[462] validation_0-rmse:8791.08789
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。