python - 如何从具有 2 个输出神经元的 softmax 二元分类器绘制 ROC 曲线?

标签 python deep-learning classification roc softmax

如何将离散输出标签绘制为 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)

最佳答案

从文档中,y_true 和 y_score 应该是 1-d。

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

y_truearray,形状 = [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

关于python - 如何从具有 2 个输出神经元的 softmax 二元分类器绘制 ROC 曲线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61086759/

相关文章:

python - 如何计算 python 中我的列中的行的编辑比/距离?

python - 用 selenium python 驱动 Opera

python - 在 Python2.7 上安装 tkMessageBox

tensorflow - 为什么我们需要使用 feed_dict 传递值来打印 TensorFlow 中的损失值

algorithm - 寻找最接近的匹配

java - 稀疏数据的离散和连续分类器

Python 3.6 - 使用异步函数进行过滤

tensorflow - 从 Keras 中的 ModelCheckpoint 检索历史对象

python - 使用双向包装器时,如何获得 LSTM 层中的最终隐藏状态和序列

linux - 混淆 ns2 : agents classifiers and nodes