0

我正在尝试为音频分类项目构建 XGBoost 分类器模型。首先,我收到错误消息“ValueError:y 应该是一维数组,而是得到一个形状为 (102, 10) 的数组。” 但是当我尝试“np.ravel(y_train)”来解决这个问题时,我得到 XGBoost 错误“标签大小必须等于行数”。正如您在代码下方看到的那样。谁能为我提供有关如何解决此问题的解决方案?

from xgboost import XGBClassifier
from sklearn.model_selection import cross_val_score

model = XGBClassifier()
model.fit(X_train,np.ravel(y_train))
model.evals_result()
score = cross_val_score(model, X_train, y_train, cv=5)
y_pred = model.predict(X_test)

count = 0
for i in range(y_pred.shape[0]):
    if y_pred[i] == y_test[i]:
        count+=1
    
print('Accuracy for model : ' + str((count / y_pred.shape[0]) * 100))`

XGBoostError                              Traceback (most recent call last)
<ipython-input-40-a4ba931a2bc5> in <module>
    4 model = XGBClassifier()
--->6 model.fit(X_train,np.ravel(y_train))
    7 model.evals_result()
    8 score = cross_val_score(model, X_train, y_train, cv=5)
XGBoostError: [16:42:08] C:/Users/Administrator/workspace/xgboost- 
win64_release_1.4.0/src/data/data.cc:583: Check failed: labels_.Size() == num_row_ (1020 vs. 102) : 
Size of labels must equal to number of rows.
4

0 回答 0