我想绘制接收者操作特征曲线,因此我做了以下操作:
from sklearn.metrics import roc_curve, aucpredictions = 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曲线“是一个图形绘图,展示了二元分类系统在其判别阈值变化时的性能”(维基百科)。
此外,“对于超过两个类别的分类问题,ROC曲线的扩展一直是繁琐的,因为自由度随类别数量的增加而呈二次增加,ROC空间具有c(c-1)个维度,其中c是类别数量。”(同一维基页面)。由于你有5个类别甚至是多标签,ROC曲线并不适合你。