roc_parw.m

来自「细胞生长结构可视化工具箱-MATLAB Toolbox1999.zip」· M 代码 · 共 82 行

M
82
字号
% Compute a Receiver Operating Characteristic Curve for the Bayesian
% version of the GCS
%
%	function GcsProj=roc_parw(GcsProj);
%

function GcsProj = roc_parw(GcsProj);

Gcs = GcsProj.Gcs;

if strcmp(Gcs.Trained,'Yes')
	%eval(['load ', filename]);

	if Gcs.NoClasses == 2
	
		%disp('NOTE: gcsbaypw.m must be run first to calulate the posterior probabilities.');
		
		temp = [-13:0.25:7];%[-7:1:5];
		temp = [-100,temp,100];	% Add extreme values to ensure we obtain ROC curve to 100% on each axis
		Thres = 2.^temp;		% Values of threshold to use 
		
		clear acc sens spec;	% prepare to recieve new results - important if No of entries in Thres are reduced
		
		for index=1:size(Thres,2)	% pos if ppos > Thres*pneg
			% Calculate the performance as a classifier
			tp(index)=0;	%No True positives 
			tn(index)=0; 	%true negatives
			fp(index)=0;	% false positives
			fn(index)=0;	% false negatives
		
			for i=1:size(Gcs.pip_1,2)	%pipneg,2)
				if (Gcs.pip_1(i)>Thres(index)*Gcs.pip_2(i))	%(pippos(i)>Thres(index)*pipneg(i))
					if Gcs.class(i) == 1
						tp(index) = tp(index)+1;	
					else
						fp(index) = fp(index)+1;
					end
				else
					if Gcs.class(i) == 2
						tn(index) = tn(index)+1;
					else
						fn(index) = fn(index)+1;
					end
				end
         end
      	acc(index) = (tp(index)+tn(index))/(tp(index)+tn(index)+fp(index)+fn(index));
			sens(index) = tp(index)/(tp(index)+fn(index));
			spec(index) = tn(index)/(tn(index)+fp(index));
      end
			area = trapz(spec,sens);
	
		%	disp('Performance of Bayes Classifier');
		%	disp(['True Positives  ',int2str(tp(index))]);
		%	disp(['True Negatives  ',int2str(tn(index))]);
		%	disp(['False Positives ',int2str(fp(index))]);
		%	disp(['False Negatives ',int2str(fn(index))]);
		%	disp(['Accuracy        ',num2str(acc(index))]);
		%	disp(['Sensitivity     ',num2str(sens(index))]);
		%	disp(['Specificity     ',num2str(spec(index))]);

		% Now plot the ROC curve
      %figure(4);
      figure;
      clf;
		%plot(1-spec,sens,'+');
		%hold on;
		plot(1-spec,sens,'-');
		hold on;
		plot([0,1],[0,1],'b--')
		axis([0,1,0,1]);
		xlabel('1-Specificity');
		ylabel('Sensitivity');
		Title('Receiver Operating Characteristic');
		disp(['Area under curve : ',num2str(area)]);

		%eval(['save ', filename]);
   end
else
   uiwait(errordlg('Network Must be trained before visualisation plots are created!'));
end 

⌨️ 快捷键说明

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