我想绘制接收器操作特性曲线,因此我执行以下操作:
from sklearn.metrics import roc_curve, auc
predictions = auto_wclf.predict_proba(X_test)
false_positive_rate, recall, thresholds = roc_curve(y_test, predictions[:, 1])
roc_auc = auc(false_positive_rate, recall)
plt.title('Receiver Operating Characteristic')
plt.plot(false_positive_rate, recall, 'b', label='AUC = %0.2f' % roc_auc)
plt.legend(loc='lower right')
plt.plot([0, 1], [0, 1], 'r--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.ylabel('Recall')
plt.xlabel('Fall-out')
plt.show()
但是我得到了这个异常:
Traceback (most recent call last):
File "plot.py", line 172, in <module>
false_positive_rate, recall, thresholds = roc_curve(y_test, predictions[:, 1])
File "plot.py", line 890, in roc_curve
y_true, y_score, pos_label=pos_label, sample_weight=sample_weight)
File "/usr/local/lib/python2.7/site-packages/sklearn/metrics/metrics.py", line 710, in _binary_clf_curve
raise ValueError("Data is not binary and pos_label is not specified")
ValueError: Data is not binary and pos_label is not specified
我有一个多标签分类问题(5 个类别)。知道如何绘制这个吗?提前谢谢大家。
最佳答案
是的,ROC 曲线“是一个图表,说明了二元分类器系统在判别阈值变化时的性能”( wiki )。
此外,“对于两个以上类别的分类问题,ROC 曲线的扩展一直很麻烦,因为自由度随着类别数量呈二次方增加,并且 ROC 空间具有 c(c-1) 维数,其中 c 是类别数。"( same wiki page ) 由于您有 5 个类别,甚至是多标签,因此 ROC 曲线不适合您。
使用类似 Hamming loss 的指标, F1-score , accuracy , precision , recall相反 - 选择最适合您任务的一个。
关于python - 使用 scikit-learn 绘制接收器操作特性时出现问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28954926/