gpt4 book ai didi

python - 如何修复 ValueError : multiclass format is not supported

转载 作者:行者123 更新时间:2023-12-04 12:24:31 25 4
gpt4 key购买 nike

这是我的代码,我尝试计算 ROC 分数,但我遇到了 ValueError 问题:不支持多类格式。我已经在寻找 sci-kit learn 但它没有帮助。最后,我仍然有 ValueError: multiclass format is not supported。

这是我的代码

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))

这是回溯

enter image description here

最佳答案

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

您的标签类别 (y) 是 10 ?如果没有,我认为您必须添加 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)

关于python - 如何修复 ValueError : multiclass format is not supported,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61114520/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com