calc_roc.m

来自「Graphical User Interface, matlab图形界面程序值得」· M 代码 · 共 78 行

M
78
字号
function calc_ROC(FX,h,handles)

% Function to plot the ROC curve and estimate the ROC area
% Written by D.LAI 2006 for D2CMatlab
% 
% FX is a m x 2 matrix with column 1 the values of the classifier decision, fx and column 2 the true label. 

[TotalRows, TotalCols]=size(FX);

handles.ROCArea=0;


% Get max and min values of FX

MAX=max(FX(1:TotalRows,1));
MIN=min(FX(1:TotalRows,1));

f1=0;
f2=0;
x1=0;
x2=0;

fmax=MIN-1;
previous=MAX+1;

% Cycle Through the Threshold
ROCData=[0 0];

for i=1:TotalRows+1

   fmax=MIN-1;
   TP=0;
   FP=0;
   TN=0;
   FN=0;
   for k=1:TotalRows
      if ( (FX(k,1)>fmax) & (FX(k,1)< previous) )
          fmax=FX(k,1);
      end       
   end
   
   CurrThres=fmax-1e-5;
   previous=fmax; 
   
   for j=1:TotalRows 
       if(FX(j,1)>CurrThres)
          if(FX(j,2)==+1)
			TP=TP+1;
		  else
			FP=FP+1;
          end
       else
          if(FX(j,1)<=CurrThres)
             if(FX(j,2)==+1)
				 FN=FN+1;
			 else
				 TN=TN+1;
             end
           end
        end
    end 
   
   f1=f2;
   f2=TP/(TP+FN);
   x1=x2;
   x2=1-TN/(TN+FP);
   
   handles.ROCData=[handles.ROCData ; x2 f2];
   handles.ROCArea= handles.ROCArea + 0.5*(x2-x1)*(f1+f2);
   
end

  guidata(h,handles);



   

⌨️ 快捷键说明

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