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

Python 如何从具有2个输出神经元的softmax二元分类器绘制ROC曲线?,python,deep-learning,classification,roc,softmax,Python,Deep Learning,Classification,Roc,Softmax,如何将离散输出标签作为两列绘制roc曲线 使用roc_曲线()会给我一个错误: 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)

如何将离散输出标签作为两列绘制roc曲线

使用roc_曲线()会给我一个错误:

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_真值和y_分数应为1-d

y\u truearray,shape=[n\u示例]

因此,只需获取标签,而不是softmax输出

在roc_曲线()之前添加以下行


由于sklearn中的
roc_曲线
函数只需要正类概率估计,因此可以使用与正类相关的输出维度

例如:
preds[:,-1]

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