当前位置:网站首页>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 .
边栏推荐
- Go basic data type conversion
- 力扣每日一题-第30天-594.最长和谐子序列
- Introduction to Ceres Quartet
- QT (x): innosetup for software packaging
- How to change the password after forgetting the MySQL password (the latest version of 2022 detailed tutorial nanny level)
- [Flink] flinksql and table programming cases
- I would like to ask what securities dealers recommend? Is it safe to open an account online?
- mongostat性能分析
- RPC和RMI
- 2022.02.14
猜你喜欢

QT writing map comprehensive application 58 compatible with multi browser kernel

JDBC连接数据库,socket发送客户端。
![[C language] flexible array](/img/22/3255740602232abfdf69624762adca.jpg)
[C language] flexible array

Part 63 - interpreter and compiler adaptation (II)

Rich material libraries make modeling easy and efficient for developers

Hyperledger Fabric 2. X custom smart contract

Installing modules in pycharm

It is the only one in China that Alibaba cloud container service has entered the Forrester leader quadrant

Pointer from beginner to advanced (2)

Clickhouse data type
随机推荐
分享 10 个 JS Promise 相关的面试题
Design and practice of kubernetes cluster and application monitoring scheme
Baidu applet automatically submits search
Installing modules in pycharm
What should I learn before learning programming?
Configuring the flutter development environment
Overlay histogram with density curve
Mongodb sort function
力扣每日一题-第30天-594.最长和谐子序列
层次分析法
Illustrate plug-in -- AI plug-in development -- creative plug-in -- astute graphics -- path width style function
Open source 23 things shardingsphere and database mesh have to say
Venn diagram proportional and color shading with semi transparency
The annual technology inventory of cloud primitives was released, and it was the right time to ride the wind and waves
Li Kou daily question - day 30 -1523 Number of bit 1
Observer mode vs publish subscribe mode
把多个ROC曲线画在一张图上
Clickhouse data type
配置Flutter开发环境
How to combine two byte arrays [repeat] - how to combine two byte arrays [duplicate]