当前位置:网站首页>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 .
边栏推荐
- Fault: administrator account cannot be selected for login
- Easy to understand TCP four waves (multi picture explanation)
- RPC和RMI
- 力扣今日题-324. 摆动排序 II
- mongostat性能分析
- Json tobean
- Li Kou daily question - day 30 -1523 Number of bit 1
- Activiti Designer
- WDCP accesses all paths that do not exist and jumps to the home page without returning 404
- QT (x): packaging and deployment
猜你喜欢

Print Yanghui triangle

package. Are you familiar with all configuration items and their usage of JSON
![[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)

The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves

UVM authentication platform

Sourcetree remote red exclamation point

Analytic hierarchy process

把多个ROC曲线画在一张图上

Annual inventory review of Alibaba cloud's observable practices in 2021

融入STEAM教育的劳动技能课程
随机推荐
Why are keys unordered in golang map
Li Kou daily question - day 30 -1523 Number of bit 1
C language pointer to function
Part 63 - interpreter and compiler adaptation (II)
[Flink] flinksql and table programming cases
Haar cascades and LBP cascades in face detection [closed] - Haar cascades vs. LBP cascades in face detection [closed]
Unity ar shadow shadow
String and variable are spliced into variable name
Where is the Gcov symbol- Where are the gcov symbols?
What are the uses of static?
Mongodb sort function
Hyperledger Fabric 2. X custom smart contract
json tobean
解析学习幼儿机器人教育的浪潮
Annual inventory review of Alibaba cloud's observable practices in 2021
2022.02.14 - 239. A single element in an ordered array
Flutter is configured with a domestic image and connected to the real machine
Li Kou today's question -324 Swing sort II
Ribbon 服务调用与负载均衡
2022.02.15 - SX10-31. House raiding III