【发布时间】:2021-05-25 14:17:58
【问题描述】:
我使用以下代码绘制了不同分类器的 ROC 曲线,但在所有图中(来自不同分类器),图表都是三角形的,如下例所示。我怎样才能有一个更流畅的情节?
def plot_roc_curve(fpr, tpr, classifier):
plt.plot(fpr, tpr, color='orange', label='ROC')
plt.plot([0, 1], [0, 1], color='darkblue', linestyle='--')
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title(str(classifier) + 'Receiver Operating Characteristic (ROC) Curve ')
plt.legend(loc="lower right")
plt.show()
from sklearn.metrics import roc_curve
fpr, tpr, thresholds = roc_curve(y_test, y_predicted)
plot_roc_curve(fpr, tpr, key)
数据集:https://www.file.io/download/Aq7LT88NBVSh
y_test
36 1
988 0
416 1
300 1
860 0
..
780 0
130 1
316 1
577 0
694 0
y_predict
[1 0 1 1 1 1 0 0 1 0 0 0 1 0 0 1 1 0 0 0 1 1 0 1 1 0 1 0 1 1 0 0 0 0 0 1 0
1 1 0 0 0 0 0 1 1 0 0 1 1 0 1 0 1 0 1 0 1 1 1 1 0 0 0 0 1 1 0 1 0 0 1 1 0
1 1 0 1 1 0 0 0 0 1 0 1 1 1 1 1 0 0 1 1 1 0 0 1 0 1 0 1 1 0 1 0 1 1 0 1 1
1 0 0 0 0 1 0 0 0 0 1 0 1 0 0 1 0 0 1 0 0 0 1 0 0 0 1 1 0 0 0 0 0 0 1 0 1
1 0 1 1 1 1 1 0 0 0 1 1 1 0 1 1 0 1 1 0 1 1 1 0 1 0 0 0 0 0 0 0 1 1 1 0 1
1 0 0 0 0 1 0 0 0 1 1 1 1 0 1 0 1 1 0 1 0 0 1 1 1 0 1 0 0 1 0 0 1 0 1 0 1
1 1 1]
【问题讨论】:
-
ROC曲线的形状取决于
y_test, y_predicted的内容,我们不知道它来自哪里。 -
那么我怎样才能像预期的图表一样标记点呢?
-
对于您提供给它的数据,这就是曲线。同样,您没有显示
y_test, y_predicted包含的内容。我只能猜测样本数量很少。 -
抱歉,我在编辑中添加了数据集。
-
y_predicted需要是非阈值,即您应该将原始置信值0.0...1.0提供给它。否则 ROC 曲线(在不同的置信度阈值下可视化行为)没有意义。
标签: python classification roc auc