How to fix ValueError: multiclass format is not supported(如何修复ValueError:不支持多类格式)
本文介绍了如何修复ValueError:不支持多类格式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码,我试图计算ROC分数,但我遇到了ValueError的问题:不支持多类格式。我已经在找科学工具包学习了,但它没有帮助。最后,我仍然有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('
Time Processing:
',time.process_time())
print('
Confussion Matrix:
', results)
print('
Zero-one classification loss:
', error)
print('
True Positive:
', TP)
print('
True Negative:
', TN)
print('
False Positive:
', FP)
print('
False Negative:
', FN)
print ('
The Classification report:
',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))
这是回溯
推荐答案
来自文档的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)
这篇关于如何修复ValueError:不支持多类格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
编程基础网
本文标题为:如何修复ValueError:不支持多类格式
基础教程推荐
猜你喜欢
- pyserial - 可以从线程 a 写入串行端口,是否阻塞从线程 b 读取? 2022-01-01
- 与常规 dict 相比,Python manager.dict() 非常慢 2022-01-01
- 使用生成器和迭代器时 Python 多循环失败 2022-01-01
- Discord.py 缺少必需的参数 2022-01-01
- 用 Python 编写 Fortran 无格式文件 2022-01-01
- 尝试制作WhatsApp机器人 2022-01-01
- 将 x 轴刻度更改为自定义字符串 2022-01-01
- numpy float:比算术运算中内置的慢 10 倍? 2022-01-01
- 由Python将MP3转换为MIDI(类型错误:无法加载插件:mtg-Melodia:Melodia) 2022-01-01
- 在 Celery 工作人员中捕获 Heroku SIGTERM 以优雅地关 2022-01-01
