[英]How to calculate one vs. one ROC for multiclass using CNN (Keras)
I am trying to get ROC for 10 classes.我正在尝试获得 10 节课的 ROC。 I have used CNN model (keras).
我使用过 CNN model (keras)。 I am able to get one vs rest curve but I want to get one vs one.
我能够得到一对 rest 曲线,但我想得到一对一。 The following is the snippet of my code.
以下是我的代码片段。
model.compile(optimizer=keras.optimizers.Adam(0.001),
loss='categorical_crossentropy',
metrics=['acc'])
from keras.callbacks import History
history = History()
model.fit_generator(generator=train_generator, callbacks= [history],
validation_data=valid_generator,epochs=10)
score = model.evaluate_generator(test_generator)
x, y = test_generator.next()
prediction = model.predict(x)
predict_label1 = np.argmax(prediction, axis=-1)
true_label1 = np.argmax(y, axis=-1)
y = np.array(true_label1)
scores = np.array(predict_label1)
fpr, tpr, thresholds = metrics.roc_curve(y, scores, pos_label=9)
roc_auc = metrics.auc(fpr, tpr)
plt.figure()
lw = 2
plt.plot(fpr, tpr, color='darkorange',
lw=lw, label='ROC curve (area = %0.2f)' % roc_auc)
plt.plot([0, 1], [0, 1], color='navy', lw=lw, linestyle='--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate')
plt.title('Receiver operating characteristic (ROC)')
plt.legend(loc="lower right")
plt.show()
This code generates one vs rest curve however I want to get the curve like this picture Is it possible to do so?此代码生成一个 vs rest 曲线但是我想得到像这张图片这样的曲线可以这样做吗? Help will be appreciated.
帮助将不胜感激。
The figure you posted illustrates a plot of multiple one vs rest ROC curves.您发布的图说明了多个一的 plot 与 rest ROC 曲线。 The blue plot is the 0class vs rest, the red plot is the 1 class vs rest, and the green plot denotes the 2 class vs rest.
The blue plot is the 0class vs rest, the red plot is the 1 class vs rest, and the green plot denotes the 2 class vs rest.
The ROC curve plots precision/recall based on various thresholds, and help find a trade-off between them. ROC 曲线根据各种阈值绘制精度/召回率,并帮助找到它们之间的权衡。 Because a threshold can't be defined in 3+ classes, we imploy a one vs rest method to enable the usage of ROC curves.
因为不能在 3 个以上的类中定义阈值,所以我们采用 one vs rest 方法来启用 ROC 曲线的使用。
I believe you could look up on some blogs on the notion of ROC curves, precision/recall, and f1 score.我相信您可以查看一些有关 ROC 曲线、精确率/召回率和 f1 分数概念的博客。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.