SVC模型-ValueError:数据不是二进制且未指定pos_label

时间:2019-05-02 22:00:26

标签: python machine-learning scikit-learn

使用Python 2.7,我试图对SVC模型的AUC和准确性得分进行网格搜索。我收到以下概述的错误。

尝试进行故障排除,无济于事。

clf = SVC(kernel = 'rbf')
parameter_grid = [
  {'C': [0.1, 1, 10, 50, 100, 400], 
   'gamma': [0.0001, 0.001, 0.01, 0.1, 1, 10]}
]

clf_stand_acc = GridSearchCV(clf, param_grid = parameter_grid)
clf_stand_acc.fit(X_train, y_train) 
y_predict_auc = clf_stand_acc.predict(X_test)


clf_stand_auc = GridSearchCV(clf, param_grid = parameter_grid, scoring = 'roc_auc')
clf_stand_auc.fit(X_train, y_train) 
y_predict_auc = clf_stand_auc.predict(X_test)

print('Test of AUC: ', roc_auc_score(y_test, y_predict_auc))

预期类似以下输出的内容。 测试集AUC:0.9993784757585

下面的实际输出的片段。

---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-47-ef06600e0bf8> in <module>()
     19 # Generate an auc object with the classifier and grid parameters.
     20 clf_stand_auc = GridSearchCV(clf, param_grid = parameter_grid, scoring = 'roc_auc')
---> 21 clf_stand_auc.fit(X_train, y_train)
     22 y_predict_auc = clf_stand_auc.predict(X_test)
     23 

ValueError: Data is not binary and pos_label is not specified

1 个答案:

答案 0 :(得分:0)

随着这个答案的出现(可能重复): ValueError: Data is not binary and pos_label is not specified

您的y_train应该如下所示:

y_train=np.array([0, 1, 0, 0, 1, 1, 1, 1, 1])

我不知道您的y值是什么样子,但这应该可以帮助您:one hot encode a binary value in numpy