function [auc, curve] = ROC(score, target, Lp, Ln)
% This function is to calculat the ordinats of points of ROC curve and the area
% under ROC curve(AUC).
% This program was described in Fawcett's paper "ROC Graphs: notes and practical
% considerations for researchers".
%
% Output:
% curve: N*3 matrix.
% the 1st column is FP
% the 2nd column is TP
% the 3rd column is score
% note: the last row, etc.the last point is [1,1,0]. if output of this
% function is applied to roc_av.m to calculate average curve of roc,
% it should be delete
% auc: scale number, area under ROC curve.
%
% Input parameters:
% score: output of classifier. high socre denote the pattern is more likely
% to be POSITIVE pattern.
% target: classlabel of each pattern.
% Lp: label of POSITIVE pattern.
% Ln: label of NEGATIVE pattern.
%
%
% QingRen (qingren_ny#126.com)
% 2006-7-20
%
len = length(score); % number of patterns
if len ~= length(target)
error('The length of tow input vectors should be equal\n');
end
P = 0; % number of Positive pattern
N = 0; % number of Negative pattern
for i = 1:len
if target(i) == Lp
P = P + 1;
elseif target(i) == Ln
N = N + 1;
else
error('Wrong target value');
end
end
% sort "L" in decending order by scores
score = score(:);
target = target(:);
L = [score target];
L = sortrows(L,1);
index = len:-1:1;
index = index'; %'
L = L(index,:);
fp = 0; fp_pre = 0; % number of False Positive pattern
tp = 0; tp_pre = 0; % number of True Positive pattern.
score_pre = -10000;
curve = [];
auc = 0;
for i = 1:len
if L(i,1) ~= score_pre
curve = [curve; [fp/N, tp/P, L(i,1)]];
auc = auc + trapezoid(fp, fp_pre, tp, tp_pre);
score_pre = L(i,1);
fp_pre = fp;
tp_pre = tp;
end
if L(i,2) == Lp
tp = tp + 1;
else
fp = fp + 1;
end
end
curve = [curve; [1,1,0]];
auc = auc / P / N;
auc = auc + trapezoid(1, fp_pre/N, 1, tp_pre/P);
% calculat the area of trapezoid
function area = trapezoid(x1,x2,y1,y2)
a = abs(x1-x2);
b = abs(y1+y2);
area = a * b / 2;
工控老马
- 粉丝: 698
- 资源: 2561
最新资源
- 员工培训需求调查问卷.doc
- 如何确定针对性的培训需求.doc
- 素质能力培训需求分析模型.doc
- 怎样进行有效的培训需求分析(doc 9).doc
- 制造业各工位培训需求.doc
- 做好培训需求分析,奠定企业员工培训的基础(DOC 8页).doc
- SQLSERVER2005卸载方法word文档doc格式最新版本
- MicrosoftSQLServer2008安装和数据库实例创建操作手册doc版冯冰最新版本
- 西电微机原理实验PDF
- P6ProfessionalSetup R24.12 安装包
- MicrosoftSQLServer2008数据库安装图解集合[特别整理版]最新版本
- 含光伏的储能选址定容模型 14节点 程序采用改进粒子群算法,对分析14节点配网系统中的储能选址定容方案,并得到储能的出力情况,有相关参考资料 这段程序是一个粒子群算法(Particle Swarm O
- PROGPPCNEXUS读写烧录刷写软件 飞思卡尔MPC55xx 56xx 57xx 58xx 没有次数限制
- 01_python_基本语法_纯图版.pdf
- 考虑新能源消纳的火电机组深度调峰策略 摘要:本代码主要做的是考虑新能源消纳的火电机组深度调峰策略,以常规调峰、不投油深度调峰、投油深度调峰三个阶段,建立了火电机组深度调峰成本模型,并以风电全额消纳为前
- EV3100电梯专用变频器源代码
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
- 1
- 2
前往页