无法创建 XGBoost DMatrix

Unable to create XGBoost DMatrix

我的理解是 DMatrix 接受 numpy.ndarray 作为输入。 我已经尝试了多次,但它不允许我创建 DMatrix。

我试过使用 Xgboost.DMatrix 和 Xgboost.sklearn.DMatrix。 任何帮助将不胜感激。

您的 y_train 似乎是一个包含非数字元素的 numpy 数组。您应该将 y_train 个元素转换为数字类型。

你可以这样做:

from sklearn import preprocessing
encoder = preprocessing.LabelEncoder()
y_train = encoder.fit_transform(y_train)