当前位置:网站首页>Draw multiple ROC curves on a graph
Draw multiple ROC curves on a graph
2022-06-29 06:51:00 【weixin_ forty-four million three hundred and twenty-three thous】
In order to show the experimental effect ,ROC Curves can also be more intuitive and beautiful . So I want to draw ROC curve . Here are two ways :1) Just draw one ROC curve ,2) Multiple ROC The curve is shown on a graph .
notes : I already have y-pred, So just use it directly , There is no need to calculate y_pred.
1 Draw a picture ROC curve
from sklearn.metrics import roc_curve, auc
import matplotlib.pyplot as plt
# Set up here lable It's really in there 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]) # Set up x、y The upper and lower limits of the axis , So as not to coincide with the edge , Better observe the whole of the image
plt.ylim([-0.05, 1.05])
plt.xlabel('False Positive Rate')
plt.ylabel('True Positive Rate') # Can use Chinese , But you need to import some libraries that are Fonts
plt.title('ROC Curve')
plt.legend(loc="lower right")
plt.show()

2 Will be multiple ROC The curve is shown on a graph
Define drawing function
def multi_models_roc(names, sampling_methods, colors, y_label, save=True, dpin=100):
"""
Combine multiple machine models roc Graph output to a graph
Args:
names: list, Names of multiple models
sampling_methods: list, Instantiated objects of multiple models
save: Choose whether to save the results ( The default is png Format )
Returns:
Return the image object 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
call multi_models_roc
names = ['UTrans_Mem',
'Unet_Mem',
]
# sampling_methods Li Wei 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')

The following links are more detailed .
边栏推荐
- 分享 10 个 JS Promise 相关的面试题
- About: deleting unwanted event log lists
- Servlet version conflict causes page 404
- Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- multi axis mirroring function
- Honeypot based on MySQL load data local INFILE
- json tobean
- Monitor employee turnover dynamics. This system makes employees tremble!
- Baidu applet automatically submits search
- Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]
- Design and practice of kubernetes cluster and application monitoring scheme
猜你喜欢

Rich material libraries make modeling easy and efficient for developers

Labor skills courses integrated into steam Education

关于DDNS

Chapter IV introduction to FPGA development platform

Li Kou today's question -324 Swing sort II

开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
![[deep learning] - maze task learning I (to realize the random movement of agents)](/img/c1/95b476ec62436a35d418754e4b11dc.jpg)
[deep learning] - maze task learning I (to realize the random movement of agents)

Pointer from beginner to advanced (2)

Json tobean

把多个ROC曲线画在一张图上
随机推荐
Pointer from beginner to advanced (2)
作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!
Share 10 interview questions related to JS promise
package. Are you familiar with all configuration items and their usage of JSON
2022.02.15 - SX10-31. House raiding III
开源二三事|ShardingSphere 与 Database Mesh 之间不得不说的那些事
Labor skills courses integrated into steam Education
How does schedulerx help users solve distributed task scheduling problems?
Monitor employee turnover dynamics. This system makes employees tremble!
VerilogA——动态比较器
UVM验证平台
[c language] [sword finger offer article] - print linked list from end to end
MySQL learning notes
Browser local storage
Where is the Gcov symbol- Where are the gcov symbols?
What are the uses of final?
C language pointer to function
Move disassembly of exclusive delivery of script (the first time)
Delete tag
[Flink] flinksql and table programming cases