【问题标题】:SVC model - ValueError: Data is not binary and pos_label is not specifiedSVC 模型 - ValueError:数据不是二进制且未指定 pos_label
【发布时间】:2019-09-21 11:15:39
【问题描述】:

使用 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

【问题讨论】:

  • 那么,您的目标是二进制文件吗?请出示您的y 的样本。
  • 我重新检查了我的特征重新编码,类标签分别是 1 和 2 而不是 1 和 0,问题已解决。

标签: python machine-learning scikit-learn


【解决方案1】:

正如这个答案所说(可能重复): 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

【讨论】:

    猜你喜欢
    • 2013-08-26
    • 2016-06-27
    • 2021-09-24
    • 2020-05-22
    • 2018-07-22
    • 2021-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多