我有这样一个数据集:
print(X_test.dtypes)
metric1 int64
rank float64
device_type int8
NA_estimate float64
当我尝试对此数据集进行预测时,我得到以下错误:
y_test_pred_xgb = clf_xgb.predict(xgb.DMatrix(X_test))
TypeError: Not supported type for data.<class 'xgboost.core.DMatrix'>
我搜索了一下,但只找到了关于引起问题的object
变量数据类型的讨论。我的数据是否存在其他问题,或者问题是否存在其他问题?我看过各种各样的博客和Kaggle代码,但运气不好
在将数据帧传递给
xgb.DMatrix
之前,使用.values
将数据帧转换为numpy数组时,我遇到了相同的错误根据下面的帖子https://datascience.stackexchange.com/a/43805/87921,我发现
xgboost
直接支持0.81版以来的pandasDataFrames
,所以调用DMatrix
是没有必要的。这在我的案例中起了作用(我使用的是1.3.3版)希望有帮助
我面临同样的问题,并通过使用
np.float32()
重新定义数据类型来解决它:相关问题 更多 >
编程相关推荐