登录  
 加关注
查看详情
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

朱振刚 日记

色谱仪,光谱仪,红外线分析器制造

 
 
 

日志

 
 

ROC曲线  

2013-09-02 19:55:05|  分类: 默认分类 |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |
最近在做一个模型,用到了ROC曲线。
ROC(Receiver Operating Characteristic,受试者工作特征的缩写)曲线是一个非常有用的技术,经常用来组织分类器,可视化分类器的性能。可作为某一诊断方法准确性评价的指标。在医学上用的较多,同样在地质领域也可以进行缓坡敏感性评价及构建成矿预测模型。
function [tp, fp] = roc(t, y)
%
% ROC - generate a receiver operating characteristic curve
%
%    [TP,FP] = ROC(T,Y) gives the true-positive rate (TP) and false positive
%    rate (FP), where Y is a column vector giving the score assigned to each
%    pattern and T indicates the true class (a value above zero represents
%    the positive class and anything else represents the negative class).  To
%    plot the ROC curve,
%
%       PLOT(FP,TP);
%       XLABEL('FALSE POSITIVE RATE');
%       YLABEL('TRUE POSITIVE RATE');
%       TITLE('RECEIVER OPERATING CHARACTERISTIC (ROC)');
%
%    See [1] for further information.
%
%    [1] Fawcett, T., "ROC graphs : Notes and practical
%        considerations for researchers", Technical report, HP
%        Laboratories, MS 1143, 1501 Page Mill Road, Palo Alto
%        CA 94304, USA, April 2004.
%
%    See also : ROCCH, AUROC
%
% File        : roc.m
%
% Date        : Friday 9th June 2005
%
% Author      : Dr Gavin C. Cawley
%
% Description : Generate an ROC curve for a two-class classifier.
%
% References  : [1] Fawcett, T., "ROC graphs : Notes and practical
%                   considerations for researchers", Technical report, HP
%                   Laboratories, MS 1143, 1501 Page Mill Road, Palo Alto
%                   CA 94304, USA, April 2004.
%
% History     : 10/11/2004 - v1.00
%               09/06/2005 - v1.10 - minor recoding
%               05/09/2008 - v2.00 - re-write using algorithm from [1]
%
% Copyright   : (c) G. C. Cawley, September 2008.
%
%    This program is free software; you can redistribute it and/or modify
%    it under the terms of the GNU General Public License as published by
%    the Free Software Foundation; either version 2 of the License, or
%    (at your option) any later version.
%
%    This program is distributed in the hope that it will be useful,
%    but WITHOUT ANY WARRANTY; without even the implied warranty of
%    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
%    GNU General Public License for more details.
%
%    You should have received a copy of the GNU General Public License
%    along with this program; if not, write to the Free Software
%    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
%
ntp = size(y,1);
% sort by classeifier output
[y,idx] = sort(y, 'descend');
t       = t(idx) > 0;
% generate ROC
P     = sum(t);
N     = ntp - P;
fp    = zeros(ntp+2,1);
tp    = zeros(ntp+2,1);
FP    = 0;
TP    = 0;
n     = 1;
yprev = -realmax;
for i=1:ntp
   if y(i) ~= yprev
      tp(n) = TP/P;
      fp(n) = FP/N; 
      yprev = y(i);
      n     = n + 1;
   end
   if t(i) == 1
      TP = TP + 1;
   else
      FP = FP + 1;
   end
end
tp(n) = 1;
fp(n) = 1;
fp    = fp(1:n);
tp    = tp(1:n);
% bye bye...

  评论这张
 
阅读(458)| 评论(0)

历史上的今天

在LOFTER的更多文章

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018