在同一图形上绘制不同nret模型的roc曲线

2024-06-26 13:38:46 发布

您现在位置:Python中文网/ 问答频道 /正文

如何在同一个图形上绘制不同模型的roc曲线? 我这样做了,但如何继续请!哦

from matplotlib import pyplot
probaA= model.predict_proba(X_testA)[:, 1]
probaB = model.predict_proba(X_testB)[:, 1] 
fpr, tpr, _ = metrics.roc_curve(y_testA,  probaA)
auc = metrics.roc_auc_score(y_testA, probaA)
pyplot.plot([0, 1], [0, 1], linestyle='--')
plt.plot(fpr,tpr,label="auc="+str(auc))
plt.legend(loc=4)
plt.show()

Tags: 图形modelplot绘制pltpredictmetricsroc
1条回答
网友
1楼 · 发布于 2024-06-26 13:38:46

如果要在同一图形中显示多条曲线,请首先使用以下方法创建轴对象:

fig, ax = plt.subplots()

使用axis对象(ax)绘制所需内容:

ax.plot(fpr_1,tpr_1,label="auc="+str(auc))
ax.plot(fpr_2,tpr_2,label="auc="+str(auc))

模型1(fpr_1,tpr_1)和模型2(fpr_2,tpr_2)的曲线应出现在同一图中

相关问题 更多 >