在用哈希进行检索时,常会用到precision recall曲线对其性能进行定量评价。precision recall的定义在信息检索评价指标中已做了详细说明,这里再记录一下precision recall的具体实现。

precision recall曲线matlab一般使用的都是下面的版本:

function [recall, precision, rate] = recall_precision(Wtrue, Dhat)
%
% Input:
%    Wtrue = true neighbors [Ntest * Ndataset], can be a full matrix NxN
%    Dhat  = estimated distances
%
% Output:
%
%                  exp. # of good pairs inside hamming ball of radius <= (n-1)
%  precision(n) = --------------------------------------------------------------
%                  exp. # of total pairs inside hamming ball of radius <= (n-1)
%
%               exp. # of good pairs inside hamming ball of radius <= (n-1)
%  recall(n) = --------------------------------------------------------------
%                          exp. # of total good pairsmax_hamm = max(Dhat(:))
hamm_thresh = min(3,max_hamm);[Ntest, Ntrain] = size(Wtrue);
total_good_pairs = sum(Wtrue(:));% find pairs with similar codes
precision = zeros(max_hamm,1);
recall = zeros(max_hamm,1);
rate = zeros(max_hamm,1);for n = 1:length(precision)j = (Dhat<=((n-1)+0.00001));%exp. # of good pairs that have exactly the same coderetrieved_good_pairs = sum(Wtrue(j));% exp. # of total pairs that have exactly the same coderetrieved_pairs = sum(j(:));precision(n) = retrieved_good_pairs/retrieved_pairs;recall(n)= retrieved_good_pairs/total_good_pairs;rate(n) = retrieved_pairs / (Ntest*Ntrain);
end% The standard measures for IR are recall and precision. Assuming that:
%
%    * RET is the set of all items the system has retrieved for a specific inquiry;
%    * REL is the set of relevant items for a specific inquiry;
%    * RETREL is the set of the retrieved relevant items
%
% then precision and recall measures are obtained as follows:
%
%    precision = RETREL / RET
%    recall = RETREL / REL% if nargout == 0 || nargin > 3
%     if isempty(fig);
%         fig = figure;
%     end
%     figure(fig)
%
%     subplot(311)
%     plot(0:hamm_thresh-1, precision(1:hamm_thresh), varargin{:})
%     hold on
%     xlabel('hamming radius')
%     ylabel('precision')
%
%     subplot(312)
%     plot(0:hamm_thresh-1, recall(1:hamm_thresh), varargin{:})
%     hold on
%     xlabel('hamming radius');
%     ylabel('recall');
%
%    subplot(313);
%     plot(recall, precision, varargin{:});
%     hold on;
%     axis([0 1 0 1]);
%     xlabel('recall');
%     ylabel('precision');
%
%     drawnow;
% end

上面画precision和recall曲线函数来自于Iterative Quantization: A Procrustean Approach to Learning Binary Codes。BRE即Code for Binary Reconstructive Hashing的代码中,同样有计算precision recall函数:

function [score, recall] = evaluation(Wtrue, Dhat, fig, varargin)
%
% Input:
%    Wtrue = true neighbors [Ntest * Ndataset], can be a full matrix NxN
%    Dhat  = estimated distances
%   The next inputs are optional:
%    fig = figure handle
%    options = just like in the plot command
%
% Output:
%
%               exp. # of good pairs inside hamming ball of radius <= (n-1)
%  score(n) = --------------------------------------------------------------
%               exp. # of total pairs inside hamming ball of radius <= (n-1)
%
%               exp. # of good pairs inside hamming ball of radius <= (n-1)
%  recall(n) = --------------------------------------------------------------
%                          exp. # of total good pairs[Ntest, Ntrain] = size(Wtrue);
total_good_pairs = sum(Wtrue(:));% find pairs with similar codes
score = zeros(20,1);
for n = 1:length(score)j = find(Dhat<=((n-1)+0.00001));%exp. # of good pairs that have exactly the same coderetrieved_good_pairs = sum(Wtrue(j));% exp. # of total pairs that have exactly the same coderetrieved_pairs = length(j);score(n) = retrieved_good_pairs/retrieved_pairs;recall(n)= retrieved_good_pairs/total_good_pairs;
end% The standard measures for IR are recall and precision. Assuming that:
%
%    * RET is the set of all items the system has retrieved for a specific inquiry;
%    * REL is the set of relevant items for a specific inquiry;
%    * RETREL is the set of the retrieved relevant items
%
% then precision and recall measures are obtained as follows:
%
%    precision = RETREL / RET
%    recall = RETREL / RELif nargout == 0 || nargin > 3if isempty(fig);fig = figure;endfigure(fig)subplot(211)plot(0:length(score)-1, score, varargin{:})hold onxlabel('hamming radium')ylabel('percent correct (precision)')title('percentage of good neighbors inside the hamm ball')subplot(212)plot(recall, score, varargin{:})hold onaxis([0 1 0 1])xlabel('recall')ylabel('percent correct (precision)')drawnow
end

不能看出,上面的score就是前面的precision,在追溯到08年,也就是谱哈希SH发表的那年,同样可以在SH中有画precision recall的曲线,跟第二个一样。考证这些,无非就是想说在自己画PR曲线时,就用这些牛提供的比较靠谱,自己写出来的不一定对。

好了,再对画precision recall输入的参数做些梳理。画precision recall曲线时,用到的groundtruth是原欧式空间中查询样本的近邻,所以在计算Wtrue时,可以采用下面的方法计算:

%center, then normalize data
X = X - ones(size(X,1),1)*mean(X);
for i = 1:size(X,1)X(i,:) = X(i,:) / norm(X(i,:));
endrp = randperm(size(X,1));
trIdx = rp(1:trN);
testIdx = rp(trN+1:trN+testN);
Xtr = X(trIdx,:);
Xtst = X(testIdx,:);D_tst = distMat(Xtst,Xtr);
D_tr = distMat(Xtr);
Dball = sort(D_tr,2);
Dball = mean(Dball(:,50));
WTT = D_tst < Dball;

上面第一步先对数据进行中心化,然后进行归一化。之后挑选出训练样本和测试样本(查询样本),然后计算Wture。Dhat就是计算查询样本与database之间的汉明距离,可以通过下面方法计算:

%get Hamming distance between queries and database
B1 = compactbit(H);
B2 = compactbit(H_query);
Dhamm = hammingDist(B2,B1);

H是database中的编码,进行压缩以十进制数进行表示,同理H_query即为查询样本的编码。将上面都计算出来后,便可以得到precision和recall,plot一下就可以了。

参考:

[1]:Code for Binary Reconstructive Hashing

查准率-查全率precision recall(PR)曲线Matlab实现相关推荐

  1. 机器学习-Precision(查准率)、Recall(查全率)、P-R曲线

    目录 前言 一.查准率P.查全率R与P-R曲线 二.Python实现 总结 前言 我们经常会关心"检索出的信息中有多少比例是用户感兴趣的""用户感兴趣的信息中有多少被检索 ...

  2. 机器学习分类器评价指标详解(Precision, Recall, PR, ROC, AUC等)(一)

    为了系统性地理解机器学习模型的不同评价指标及其之间的关系,我们将从其定义出发,探究其物理含义及彼此之间的联系,并从数学上给出相应的公式推导,以方便后续用到时复习理解.由于篇幅较长,因此将其分为两篇,这 ...

  3. matlab drawnow连成曲线,precision recall曲线Matlab实现

    在用哈希进行检索时,常会用到precision recall曲线对其性能进行定量评价.precision recall的定义在信息检索评价指标中已做了详细说明,这里再记录一下precision rec ...

  4. 图片检索matlab程序,图像检索:precision recall曲线Matlab实现

    在用哈希进行检索时,常会用到precision recall曲线对其性能进行定量评价.precision recall的定义在信息检索评价指标中已做了详细说明,这里再记录一下precision rec ...

  5. 『论文阅读笔记』目标检测模型中的性能评价方式-IOU、precision/recall、mAP、PR、Fps!

    目标检测模型中的性能评估标准-IOU.precision/recall.mAP.PR.Fps! 文章目录 一.交并比IOU 二.精确率(precision)和召回率(recall) 三.P-R(pre ...

  6. 【机器学习-西瓜书】二、性能度量:召回率;P-R曲线;F1值;ROC;AUC

    关键词:准确率(查准率,precision):召回率(查全率,recall):P-R曲线,平衡点(Break-Even Point, BEP):F1值,F值:ROC(Receiver Operatin ...

  7. P-R曲线与ROC曲线使用总结

    P-R曲线与ROC曲线总结 作者:jliang https://blog.csdn.net/jliang3 1.P-R曲线 1)实际预测时二分类的四种情况 真阳性/真正类(True Positive, ...

  8. Sklearn XGBoost模型算法分类建模-----风控项目实战(PR曲线、KS、AUC、F1-Score各类指标)

    项目背景:二手手机需从前端质检项推断手机有无拆修问题 思路: a)X值:前端各类质检项,对应映射ID+RANK值(涉及质检项会有等级排序,需进行RANK排序(属性值RANK一般需手工或是系统配置时候就 ...

  9. 机器学习:关于P-R曲线和Roc曲线

    一:关于P-R曲线:     1:1:何为P-R曲线: P为precision即精准率(查准率),R为recall即召回率,所以P-R曲线是反映了准确率与召回率之间的关系.一般横坐标为recall,纵 ...

最新文章

  1. 关于Combobox的多选和单选情况
  2. jquery 重写 html5 验证,Jquery前端滑动验证方式功能实现
  3. VTK:Snippets之RestoreSceneFromFieldData
  4. JRE里居然隐藏了一个自带的js engine
  5. CPU上跑深度学习模型,FPS也可以达100帧
  6. 重写对象的equals和hashCode方法
  7. 简单3小步,轻松搞定PS证件照换底色(有手就行)
  8. 蓝绿部署、滚动部署、灰度部署、金丝雀部署
  9. -bash:/etc/profile: line 21: syntax error near unexpected token `$‘do\r‘‘
  10. bibtex 共生_游戏与音乐的共生
  11. 苹果电脑Mac中delete键的七种用法
  12. Link context for 0x01 connection handle could not be fetched.
  13. java及历史版本下载
  14. dSYM文件解析与分析
  15. 优秀WinRT用户界面开发工具推荐
  16. 工作中打印机驱动下载方式
  17. 【软件测试基本流程】
  18. centos7安装ZipArchive
  19. jython 导入java包_在jython中导入java类
  20. 相机调试-清晰度sharpness

热门文章

  1. 微信小程序原生接入腾讯云im(单聊,列表,聊天界面,自定义消息,自动回复)
  2. 限时福利!技术大牛给你送书了
  3. 如何确认W5500网络芯片物理连接是否正常?
  4. 宁波学python_宁波多久能学会python(学了Python)
  5. linux内核enforcing引导参数
  6. R语言使用dplyr包的group_by函数和summarise函数基于分组变量计算目标变量的均值、标准差
  7. 本“徕”就美,Xiaomi 12S 系列原生双画质的修炼秘籍
  8. Android按键面板上所有物理按键均可唤醒屏幕
  9. 荣耀v30是安卓还是鸿蒙,荣耀30、V30和20系列等用户有福啦
  10. Responder 嗅探/欺骗工具