Machine learning 将错误获取为DataFrame.d数据类型必须为int、float、bool或category
XGBOOST中的完全错误为Machine learning 将错误获取为DataFrame.d数据类型必须为int、float、bool或category,machine-learning,time-series,xgboost,Machine Learning,Time Series,Xgboost,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
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
我哪里错了,如果你需要什么,请问我
谢谢你的帮助
编辑:
我将年份类型转换为字符串,然后转换为int
但结果是这样的,
[461] validation_0-rmse:8791.25293
[462] validation_0-rmse:8791.08789
您在
X\u列车
和X\u测试
中的变量Year
是一个日期。它不是“int、float、bool或categorical”。是的,那么,如何继续@DavidM。?如果Year
不是预测值,您可以删除它。相反,如果C_Id
和R_Id
不是预测因子,则应删除它们并执行。如果你想保留所有的协变量,你需要使用XGBoost和多变量输入(见上一链接)。好的,C_id和R_id是作物id和区域id,所以我认为它们会起到重要作用。你的变量X_train
中的Year
和X_test
是一个日期。它不是“int、float、bool或categorical”。是的,那么,如何继续@DavidM。?如果Year
不是预测值,您可以删除它。相反,如果C_Id
和R_Id
不是预测因子,则应删除它们并执行。如果你想保留所有的协变量,你需要使用XGBoost和多变量输入(见上一个链接)。好的,C_id和R_id是作物id和区域id,所以我认为它们将发挥重要作用。
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)
[461] validation_0-rmse:8791.25293
[462] validation_0-rmse:8791.08789