学习文档接触到的知识VER

看一个文档,很多不知道的知识,感谢网上有这么多丰富的知识,帮我解答。互联网真是一个好东西

微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑微笑


 1、import matplotlib.pyplot as plt    #Matplotlib是Python中最常用的可视化工具之一
查阅的知识: #导入pyplot,文档里面的例子通常将其别名为plt
import matplotlib.pyplot as plt
#创建一幅图
plt.figure()
#画出曲线
plt.plot(x,y)
#显示
plt.show()
文档中的应用:
        plt.figure()    #plt,python的可视化工具,函数设计上参考MATLAB。
        plt.plot(fprs, tprs, label='ROC curve (AUC = %0.2f)' % auc)
        plt.plot([0, 1], [0, 1], color='navy', linestyle='--')
        plt.xlim([-0.01, 1.0])   #X轴上下限设定
        plt.xlabel('False Positive (fp)') ##横X坐标标题为: 'False Positive Rate (fp)'
        plt.title('12')
        plt.legend(loc="lower right")  #图片的显示位置  

2、from sklearn.metrics import roc_curve,average_precision_score
查阅的知识:  
sklearn.metric提供了一些函数,用来计算真实值与预测值之间的预测误差: 以_score结尾的函数,返回一个最大值,越高越好
#average_precision_score计算平均精度    precision = TP / (TP + FP)  
precision_recall_curve会根据预测值和真实值来计算一条precision-recall典线。
average_precision_score则会预测值的平均准确率(AP: average precision)。该分值对应于precision-recall曲线下的面积。
sklearn提供了一些函数来分析precision, recall and F-measures值:
average_precision_score:计算预测值的AP
#roc_curve计算roc曲线,属性有fpr,tpr,阈值。
roc_curve计算了ROC曲线。
该函数需要二分类的真实值和预测值,它可以是正例的概率估计,置信值,或二分决策值。roc_auc_score函数计算了ROC曲线下面的面积,它也被称为AUC或AUROC。通过计算下面的面积,曲线信息被归一化到1内。
文档中的应用:
fprs,tprs,threshs=roc_curve(gt,scores,pos_label=1)
ap=average_precision_score(gt,scores) 


3、 gt=np.loadtxt(gt_name)   #np.loadtxt读取图片序列数组
查阅的知识:
numpy读取文本文件Text files
loadtxt(fname[, dtype, comments, delimiter, ...]) Load data from a text file.
savetxt(fname, X[, fmt, delimiter, newline, ...]) Save an array to a text file.
genfromtxt(fname[, dtype, comments, ...]) Load data from a text file, with missing values handled as specified.
fromregex(file, regexp, dtype)          Construct an array from a text file, using regular expression parsing.
fromstring(string[, dtype, count, sep]) A new 1-D array initialized from raw binary or text data in a string.
ndarray.tofile(fid[, sep, format])     Write array to a file as text or binary (default).
ndarray.tolist()               Return the array as a (possibly nested) list.


4、 scores=np.zeros(num_pairs)
查阅的知识:
用法:zeros(shape, dtype=float, order='C')
返回:返回来一个给定形状和类型的用0填充的数组;
参数:shape:形状
            dtype:数据类型,可选参数,默认numpy.float64
np.zeros(5)
array([ 0.,  0.,  0.,  0.,  0.])


5、 right=np.sum(pred==gt)     |||||||||||依旧不懂什么意思
查阅的知识:
>>> a=np.sum([[0,1,2],[2,1,3]],axis=1)  
>>> a  
array([3, 6])  
>>> a.shape  
(2,)  


6、np.logical_and(pred,gt)    
查阅的知识:
 #Python 中的布尔运算使用and、or 和not ,以“logical_”开头,np.logical_and, np.logical_not, np.logical_or, np.logical_xor


7、gt=np.array(gt).astype(np.bool)     ?不确定
查阅的知识:
#bool布尔型,取值False或True     .astype实现变量类型转换  将gt转换为布尔值


8、pred=scores>thres      #如果scores> thres ,那么pred为True 


9、for thresh in np.linspace(1e-7,0.6,3000):    #np.linspace 生成等间隔数列,在(1e-7,0.6)之间有3000份


10、sortedFprs.append(1.0)   #在原有列表上追加一个新元素
        
11、sortedFprs, sortedTprs = zip(*sorted(zip(*(fprs, tprs))))  #压缩后排序,即将两个一维数组压缩成一个二维数组
查阅的知识:
x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
xyz = zip(x, y, z)
print xyz
运行的结果:[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
x = [1, 2, 3]
y = [4, 5, 6]
z = [7, 8, 9]
xyz = zip(x, y, z)
u = zip(*xyz)
print u
运行的结果是:
[(1, 2, 3), (4, 5, 6), (7, 8, 9)]
一般认为这是一个unzip的过程,它的运行机制是这样的:
在运行zip(*xyz)之前,xyz的值是:[(1, 4, 7), (2, 5, 8), (3, 6, 9)]
那么,zip(*xyz) 等价于 zip((1, 4, 7), (2, 5, 8), (3, 6, 9))
所以,运行结果是:[(1, 2, 3), (4, 5, 6), (7, 8, 9)]


12、 index=np.array(a).argmax()         #numpy.argmax(a, axis=None, out=None) 返回沿轴axis最大值的索引。!!!!!索引
查阅的知识:
>>> a = np.arange(6).reshape(2,3)
>>> a
array([[0, 1, 2],
       [3, 4, 5]])
>>> np.argmax(a)
5
>>> np.argmax(a, axis=0)#0代表列
array([1, 1, 1])
>>> np.argmax(a, axis=1)#1代表行    ????看不懂
array([2, 2])
>>>
>>> b = np.arange(6)
>>> b[1] = 5
>>> b
array([0, 5, 2, 3, 4, 5])
>>> np.argmax(b) # 只返回第一次出现的最大值的索引
1


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值