【问题标题】:How to fix ValueError: multiclass format is not supported如何修复 ValueError:不支持多类格式
【发布时间】:2020-07-21 16:21:00
【问题描述】:

这是我的代码,我尝试计算 ROC 分数,但 ValueError 出现问题:不支持多类格式。我已经在寻找 sci-kit 学习,但它没有帮助。最后,我仍然有ValueError:不支持多类格式。

这是我的代码

from sklearn.tree import DecisionTreeClassifier
from sklearn.ensemble import BaggingClassifier
from sklearn.metrics import confusion_matrix,zero_one_loss
from sklearn.metrics import classification_report,matthews_corrcoef,accuracy_score
from sklearn.metrics import roc_auc_score, auc


dtc = DecisionTreeClassifier()
bc = BaggingClassifier(base_estimator=dtc, n_estimators=10, random_state=17)
bc.fit(train_x, train_Y)
pred_y = bc.predict(test_x)

fprate, tprate, thresholds = roc_curve(test_Y, pred_y)
results = confusion_matrix(test_Y, pred_y)
error = zero_one_loss(test_Y, pred_y)
roc_auc_score(test_Y, pred_y)

FP = results.sum(axis=0) - np.diag(results)  
FN = results.sum(axis=1) - np.diag(results)
TP = np.diag(results)
TN = results.sum() - (FP + FN + TP)



print('\n Time Processing: \n',time.process_time())
print('\n Confussion Matrix: \n', results)
print('\n Zero-one classification loss: \n', error)
print('\n True Positive: \n', TP)
print('\n True Negative: \n', TN)
print('\n False Positive: \n', FP)
print('\n False Negative: \n', FN)
print ('\n The Classification report:\n',classification_report(test_Y,pred_y, digits=6))
print ('MCC:', matthews_corrcoef(test_Y,pred_y))
print ('Accuracy:', accuracy_score(test_Y,pred_y))
print (auc(fprate, tprate))
print ('ROC Score:', roc_auc_score(test_Y,pred_y))

这是回溯

【问题讨论】:

  • 请添加错误信息以便我们能够追踪行号和信息
  • 是的,我已经在问题中提出了错误
  • 您能否发布完整的回溯,以便我们查看您的代码中的哪一行导致了错误?截至目前,它仅显示 sci-kit 学习库中发生错误的位置,这并不是特别有用
  • 好的我已经放好了

标签: python scikit-learn spyder roc


【解决方案1】:

来自文档,roc_curve:“注意:此实现仅限于二进制分类任务。”

您的标签类别 (y) 是 1 还是 0?如果没有,我认为您必须将pos_label 参数添加到您的roc_curve 调用中。

fprate, tprate, thresholds = roc_curve(test_Y, pred_y, pos_label='your_label')

或者:

test_Y = your_test_y_array  # these are either 1's or 0's
fprate, tprate, thresholds = roc_curve(test_Y, pred_y)

【讨论】:

    猜你喜欢
    • 2020-02-14
    • 2017-10-19
    • 2017-11-12
    • 2014-11-30
    • 2018-11-07
    • 2019-10-01
    • 1970-01-01
    • 2012-09-17
    • 2020-06-05
    相关资源
    最近更新 更多