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;

工控老马
- 粉丝: 751
最新资源
- 科技管理系统如何借助AI+数智应用突破传统,实现高效管理与创新服务?.docx
- 科技管理系统如何通过AI+数智应用实现深层次的价值创造?.docx
- 面对AI+数智应用和大数据等新技术,科技管理系统如何实现智能化升级?.docx
- 面对复杂的科技管理工作,如何借助AI+数智应用构建个性化且高效的服务体系?.docx
- 面对科技管理系统升级的挑战,有哪些AI+数智应用解决方案能够助力企业突破瓶颈?.docx
- 如何借助AI+数智应用解决科技管理系统中存在的自主驱动不足与价值创造受限问题?.docx
- 如何借助AI+数智应用技术提升科研项目管理水平?.docx
- 如何借助AI+数智应用科技管理解决方案实现深层次价值创造?.docx
- 如何借助AI+数智应用实现技术转移服务的降本增效?.docx
- 如何借助AI+数智应用提高技术转移服务效率?.docx
- 如何借助AI+数智应用突破传统科技管理系统的局限,实现高效管理与价值创造?.docx
- 如何借助AI+数智应用突破传统科技管理系统局限,实现管理与服务融合及价值创造?.docx
- 如何利用AI+数智应用和大数据分析技术优化科技管理服务流程?.docx
- 如何利用AI+数智应用分析不同技术转移服务类别,以应对多维挑战?.docx
- 如何利用AI+数智应用技术解决技术转移服务成本高昂的问题?.docx
- 如何利用AI+数智应用技术提升科技管理系统的智能化水平?.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈



- 1
- 2
前往页