当前位置:网站首页>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 .
边栏推荐
- Why should enterprises do more application activities?
- [Flink] flinksql and table programming cases
- Analytic hierarchy process
- idea使用
- Unity ar shadow shadow
- QT writing map comprehensive application 58 compatible with multi browser kernel
- 2022.02.14
- Clickhouse data type
- Benign competition will promote each other
- 作为一名合格的网工,你必须掌握的 DHCP Snooping 知识!
猜你喜欢

Delete tag

json tobean

QT (x): innosetup for software packaging

mongostat性能分析

package. Are you familiar with all configuration items and their usage of JSON

Li Kou today's question -324 Swing sort II

Service grid ASM year end summary: how do end users use the service grid?

层次分析法

Redistemplate handles hash integer type problem resolution

Design and practice of kubernetes cluster and application monitoring scheme
随机推荐
Annual inventory review of Alibaba cloud's observable practices in 2021
json tobean
Redistemplate handles hash integer type problem resolution
Creating a new generation of production and service tools with robot education
力扣每日一题-第30天-594.最长和谐子序列
Labor skills courses integrated into steam Education
多线程工具类 CompletableFuture
VerilogA - counter
JDBC连接数据库,socket发送客户端。
How to do the performance pressure test of "Health Code"
Servlet version conflict causes page 404
What is the "danksharding" of V God Kop on Valentine's day?
Fault: ntfrs warning log for id13562
WDCP accesses all paths that do not exist and jumps to the home page without returning 404
Difference between static and final
VerilogA——计数器
Antd work item memo w3.0
Json tobean
Games101 Lecture 10 geometry 1 Notes
二叉树的迭代法前序遍历的两种方法