python 画roc曲线
【摘要】
label.txt:
1
0
1
0
1
0
feature.txt
0.1
0.2
0.2
0.2
0.2
0.3
代码:
# -*- coding: utf-8 -*- import math import sklearn import numpy as np import matplotlib.pyplot as ...
label.txt:
1
0
1
0
1
0
feature.txt
0.1
0.2
0.2
0.2
0.2
0.3
代码:
# -*- coding: utf-8 -*-
import math
import sklearn
import numpy as np
import matplotlib.pyplot as plt
import skimage
import sklearn.metrics.pairwise as pw
#读取标签文件
def read_labels(labelfile):
fin=open(labelfile)
lines=fin.readlines()
labels=np.empty((len(lines),))
k=0;
for line in lines:
labels[k]=int(line)
k=k+1;
fin.close()
return labels
def read_Feautures(labelfile):
fin=open(labelfile)
lines=fin.readlines()
labels=np.empty((len(lines),))
k=0;
for line in lines:
labels[k]=float(line)
k=k+1;
fin.close()
return labels
#画ROC曲线图
def draw_roc_curve(fpr1,tpr1,fpr2,tpr2, title='cosine',save_name='roc_lfw'):
plt.figure()
plt.plot(fpr1, tpr1,'r')
plt.plot(fpr2, tpr2,'g')
plt.plot([0, 1], [0, 1], 'k--')
plt.xlim([0.0, 1.0])
plt.ylim([0.0, 1.0])
plt.xlabel('FPR')
plt.ylabel('TPR')
plt.title('ROC(Receiver operating characteristic)using: '+title)
plt.legend(loc="lower right")
plt.show()
plt.savefig(save_name+'.png')
if __name__=='__main__':
labels = read_labels(u"label.txt")
predicts = read_Feautures(u"feature.txt")
fpr1, tpr1, threshold1s=sklearn.metrics.roc_curve(labels,predicts)
print(threshold1s)
#draw_roc_curve(fpr1,tpr1,title='JSS',save_name='lfw_evaluate')
labels = read_labels(u"label.txt")
predicts = read_Feautures(u"feature.txt")
fpr2, tpr2, threshold2s=sklearn.metrics.roc_curve(labels,predicts)
print(threshold2s)
draw_roc_curve(fpr1,tpr1,fpr2,tpr2,title='AS',save_name='lfw_evaluate')
文章来源: blog.csdn.net,作者:AI视觉网奇,版权归原作者所有,如需转载,请联系作者。
原文链接:blog.csdn.net/jacke121/article/details/120818500
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
作者其他文章
评论(0)