basicroc.m

来自「最详尽的神经网络源码」· M 代码 · 共 69 行

M
69
字号
function [tp , fp , threshold] = basicroc(y , f , options)

%
%[tp , fp , threshold] = basicroc(y , f , [positive]);
%
% Return the true positive rate, the false positive rate and the threshold
%
%
%  Author : S閎astien PARIS : sebastien.paris@lsis.org
%  -------  Date : 04/09/2006



if nargin < 3
    
    options.positive = 1;
    
    options.nbstep   = 100;
    
end

if (~any(strcmp(fieldnames(options) , 'positive')))

    options.positive = 1;

end

if (~any(strcmp(fieldnames(options) , 'nbstep')))

    options.nbstep   = 100;

end


yunique            = unique(y);
bin                = histc(y , yunique);

index              = (yunique==options.positive);

P                  = bin(index); %(y = positive)
N                  = sum(bin(~index)); %(y = else)

minf               = min(f);
maxf               = max(f);
stepf              = (maxf - minf)/(options.nbstep - 3);

threshold          = (maxf:-stepf:minf);

tp                 = zeros(1 , options.nbstep - 2);
fp                 = zeros(1 , options.nbstep - 2);

co                 = 1;
for t = threshold
    
    ind       = (y(f>threshold(co))==options.positive);
    
    tp(co)    = sum(ind)/P;
    fp(co)    = sum(~ind)/N; 
    co        = co + 1;
    
end

tp                 = [0 , tp , 1];
fp                 = [0 , fp , 1];




⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?