【问题标题】:How to plot a ROC curve from a softmax binary classifier with 2 output neurons?如何从具有 2 个输出神经元的 softmax 二元分类器绘制 ROC 曲线?
【发布时间】:2020-07-20 01:01:19
【问题描述】:

如何将离散输出标签绘制为 2 列的 roc 曲线?

使用 roc_curve() 给我一个错误:

ValueError:不支持多标签指示符格式

y_prediction = model.predict(test_X)

y_prediction[1]
Out[27]: array([1.0000000e+00, 6.8178085e-12], dtype=float32)

y_prediction.shape
Out[23]: (514, 2)

test_y.shape
Out[24]: (514, 2)

fpr_roc, tpr_roc, thresholds_roc = roc_curve(test_y, y_prediction)

roc_auc = metrics.auc(fpr_roc, tpr_roc)

【问题讨论】:

    标签: python deep-learning classification roc softmax


    【解决方案1】:

    根据文档,y_true 和 y_score 应该是 1-d。

    https://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc_curve.html

    y_truearray, shape = [n_samples]

    所以,只取标签而不是 softmax 输出。

    在 roc_curve() 之前添加以下行

    test_y = np.argmax(test_y, axis=-1) # getting the labels
    y_prediction = np.argmax(y_prediction, axis=-1) # getting the confidence of postive class
    

    【讨论】:

      【解决方案2】:

      由于sklearn中的roc_curve函数只需要正类概率估计,所以可以使用与正类相关的输出维度。

      例如: preds[:, -1]

      【讨论】:

        猜你喜欢
        • 2020-09-19
        • 2016-07-22
        • 2014-01-03
        • 2018-12-19
        • 2018-11-29
        • 2018-09-11
        • 2018-05-24
        • 2020-07-21
        • 2015-07-20
        相关资源
        最近更新 更多