当前位置:网站首页>把多个ROC曲线画在一张图上
把多个ROC曲线画在一张图上
2022-06-29 06:37:00 【weixin_44323744】
为了展示实验效果,ROC曲线也能更直观的展示而且美观。所以我想画出ROC曲线。下面是两个方法:1)只画一个ROC曲线,2)多个ROC曲线展示在一张图上。
注:我是已经有y-pred,所以直接用即可,不需要在计算y_pred。
1 画一个ROC曲线
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt
# 这里设置lable里真是1.
fpr, tpr, thersholds = roc_curve(y_label, y_pred, pos_label=1)
for i, value in enumerate(thersholds):
print("%f %f %f" % (fpr[i], tpr[i], value))
roc_auc = auc(fpr, tpr)
plt.figure(figsize=(10, 10), dpi=100)
plt.plot(fpr, tpr, 'k--', label='ROC (area = {0:.2f})'.format(roc_auc), lw=2)
plt.xlim([-0.05, 1.05]) # 设置x、y轴的上下限,以免和边缘重合,更好的观察图像的整体
plt.ylim([-0.05, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate') # 可以使用中文,但需要导入一些库即字体
plt.title('ROC Curve')
plt.legend(loc="lower right")
plt.show()

2 将多个ROC曲线展示在一张图上
定义画图函数
def multi_models_roc(names, sampling_methods, colors, y_label, save=True, dpin=100):
"""
将多个机器模型的roc图输出到一张图上
Args:
names: list, 多个模型的名称
sampling_methods: list, 多个模型的实例化对象
save: 选择是否将结果保存(默认为png格式)
Returns:
返回图片对象plt
"""
plt.figure(figsize=(10, 10), dpi=dpin)
for (name, y_pred, colorname) in zip(names, sampling_methods, colors):
fpr, tpr, thresholds = roc_curve(y_label, y_pred, pos_label=1)
plt.plot(fpr, tpr, lw=5, label='{} (AUC={:.3f})'.format(name, auc(fpr, tpr)),color = colorname)
plt.plot([0, 1], [0, 1], '--', lw=5, color = 'grey')
plt.axis('square')
plt.xlim([0, 1])
plt.ylim([0, 1])
plt.xlabel('False Positive Rate',fontsize=20)
plt.ylabel('True Positive Rate',fontsize=20)
plt.title('ROC Curve',fontsize=25)
plt.legend(loc='lower right',fontsize=20)
if save:
plt.savefig('multi_models_roc.png')
return plt
调用multi_models_roc
names = ['UTrans_Mem',
'Unet_Mem',
]
# sampling_methods里为 y_pred.
sampling_methods = [preds_UT_mem,
preds_U_mem,
]
#color:'crimson','orange','gold','mediumseagreen','steelblue', 'mediumpurple'
colors = ['crimson',
'orange',
]
#ROC curves
train_roc_graph = multi_models_roc(names, sampling_methods, colors, label[0], save = True)
train_roc_graph.savefig('ROC_Train_all.png')

下面的链接里又更详细的介绍。
(56条消息) python 将多个模型的ROC曲线绘制在一张图里(含图例)_柳奈奈的博客-CSDN博客_pytorch多分类roc曲线绘制
边栏推荐
- Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function
- Sum of digits under k-ary representation of leetcode simple problem
- Longest substring between two identical characters of leetcode simple question
- 2022.02.15 - SX10-31. House raiding III
- Analysis on the wave of learning robot education for children
- Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- multi axis mirroring function
- Honeypot based on MySQL load data local INFILE
- [Flink] flinksql and table programming cases
- json tobean
- The generation of leetcode simple questions each character is an odd number of strings
猜你喜欢

Small program large screen adaptation Guide

RPC和RMI

分享 10 个 JS Promise 相关的面试题

Installing modules in pycharm

关于 localStorage 的一些高阶用法

Labor skills courses integrated into steam Education

Pointer from beginner to advanced (2)

Share 10 interview questions related to JS promise

Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- length and angle measurement function

Design of leetcode simple problem goal parser
随机推荐
Fault: administrator account cannot be selected for login
Object detection - VIDEO reasoning using yolov6
Difference between static and final
[C language] flexible array
MySQL learning notes
Can I cast int to a variable of type byte? What happens if the value is larger than the range of byte type?
2022.02.15 - 240. Lucky number in matrix
National Defense University project summary
try anbox (by quqi99)
Test Development - ten years of sharpening one sword (VII) interface test tool postman
After “Go to Definition”, is there a command to return to where you came from?
I would like to ask what securities dealers recommend? Is it safe to open an account online?
Failure: unable to log in to "taxpayer equity platform"
QT (x): innosetup for software packaging
力扣今日题-324. 摆动排序 II
Mongodb paging method
Fault: ntfrs warning log for id13562
Activiti Designer
Fresnel diffraction with rectangular aperture based on MATLAB
Labor skills courses integrated into steam Education