【问题标题】:How to smooth ROC curve?如何平滑 ROC 曲线?
【发布时间】: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


【解决方案1】:

您正在使用阈值预测来生成 ROC 曲线。您应该改用原始置信度值,否则您只会在曲线上获得 1 个中间点。

这是一些示例数据和您将获得的 ROC 曲线。

y_test: [1, 0, 0, 0, 0, 1, 0, 0, 0, 0, ...
y_predicted: [1, 0.405, 0.601, 0.579, 0.03, 0.98, 0.06, 0.242, 0.379, 0.09, ...
y_predicted_thresholded: [1, 0, 1, 1, 0, 1, 0, 0, 0, 0, ...

【讨论】:

    猜你喜欢
    • 2019-02-27
    • 2019-11-25
    • 2018-12-28
    • 2021-01-30
    • 1970-01-01
    • 2021-11-28
    • 2018-12-27
    • 2012-10-10
    • 2019-06-21
    相关资源
    最近更新 更多