function ROCout=roc(varargin)
% ROC - Receiver Operating Characteristics.
% The ROC graphs are a useful tecnique for organizing classifiers and
% visualizing their performance. ROC graphs are commonly used in medical
% decision making.
% If you have not downloaded partest
% http://www.mathworks.com/matlabcentral/fileexchange/12705
% and L5P
% http://www.mathworks.com/matlabcentral/fileexchange/38043
% the routine will do and compute several data on test performance.
%
% Syntax: ROCout=roc(x,thresholds,alpha,verbose)
%
% Input: x - This is a Nx2 data matrix. The first column is the column of the data value;
% The second column is the column of the tag: unhealthy (1) and
% healthy (0).
% Thresholds - If you want to use all unique values in x(:,1)
% then set this variable to 0 or leave it empty;
% else set how many unique values you want to use (min=3);
% alpha - significance level (default 0.05)
% verbose - if you want to see all reports and plots (0-no; 1-yes by
% default);
%
% Output: if verbose = 1
% the ROCplots, the sensitivity and specificity at thresholds; the Area
% under the curve with Standard error and Confidence interval and
% comment, Cut-off point for best sensitivity and specificity.
% (Optional) the test performances at cut-off point.
% if ROCout is declared, you will have a struct:
% ROCout.AUC=Area under the curve (AUC);
% ROCout.SE=Standard error of the area;
% ROCout.ci=Confidence interval of the AUC
% ROCout.co=Cut off points
% ROCdata.xr and ROCdata.yr points for ROC plot
%
% USING roc WITHOUT ANY DATA, IT WILL RUN A DEMO
%
% Created by Giuseppe Cardillo
% [email protected]
%
% To cite this file, this would be an appropriate format:
% Cardillo G. (2008) ROC curve: compute a Receiver Operating Characteristics curve.
% http://www.mathworks.com/matlabcentral/fileexchange/19950
%Input Error handling
args=cell(varargin);
nu=numel(args);
if isempty(nu)
error('Warning: almost the data matrix is required')
elseif nu>4
error('Warning: Max four input data are required')
end
default.values = {[165 1;140 1;154 1;139 1;134 1;154 1;120 1;133 1;150 1;...
146 1;140 1;114 1;128 1;131 1;116 1;128 1;122 1;129 1;145 1;117 1;140 1;...
149 1;116 1;147 1;125 1;149 1;129 1;157 1;144 1;123 1;107 1;129 1;152 1;...
164 1;134 1;120 1;148 1;151 1;149 1;138 1;159 1;169 1;137 1;151 1;141 1;...
145 1;135 1;135 1;153 1;125 1;159 1;148 1;142 1;130 1;111 1;140 1;136 1;...
142 1;139 1;137 1;187 1;154 1;151 1;149 1;148 1;157 1;159 1;143 1;124 1;...
141 1;114 1;136 1;110 1;129 1;145 1;132 1;125 1;149 1;146 1;138 1;151 1;...
147 1;154 1;147 1;158 1;156 1;156 1;128 1;151 1;138 1;193 1;131 1;127 1;...
129 1;120 1;159 1;147 1;159 1;156 1;143 1;149 1;160 1;126 1;136 1;150 1;...
136 1;151 1;140 1;145 1;140 1;134 1;140 1;138 1;144 1;140 1;140 1;159 0;...
136 0;149 0;156 0;191 0;169 0;194 0;182 0;163 0;152 0;145 0;176 0;122 0;...
141 0;172 0;162 0;165 0;184 0;239 0;178 0;178 0;164 0;185 0;154 0;164 0;...
140 0;207 0;214 0;165 0;183 0;218 0;142 0;161 0;168 0;181 0;162 0;166 0;...
150 0;205 0;163 0;166 0;176 0;],0,0.05,1};
default.values(1:nu) = args;
[x threshold alpha verbose] = deal(default.values{:});
if isvector(x)
error('Warning: X must be a matrix')
end
if ~all(isfinite(x(:))) || ~all(isnumeric(x(:)))
error('Warning: all X values must be numeric and finite')
end
x(:,2)=logical(x(:,2));
if all(x(:,2)==0)
error('Warning: there are only healthy subjects!')
end
if all(x(:,2)==1)
error('Warning: there are only unhealthy subjects!')
end
if nu>=2
if isempty(threshold)
threshold=0;
else
if ~isscalar(threshold) || ~isnumeric(threshold) || ~isfinite(threshold)
error('Warning: it is required a numeric, finite and scalar THRESHOLD value.');
end
if threshold ~= 0 && threshold <3
error('Warning: Threshold must be 0 if you want to use all unique points or >=2.')
end
end
if nu>=3
if isempty(alpha)
alpha=0.05;
else3
if ~isscalar(alpha) || ~isnumeric(alpha) || ~isfinite(alpha)
error('Warning: it is required a numeric, finite and scalar ALPHA value.');
end
if alpha <= 0 || alpha >= 1 %check if alpha is between 0 and 1
error('Warning: ALPHA must be comprised between 0 and 1.')
end
end
end
if nu==4
verbose=logical(verbose);
end
end
clear args default nu
tr=repmat('-',1,80);
lu=length(x(x(:,2)==1)); %number of unhealthy subjects
lh=length(x(x(:,2)==0)); %number of healthy subjects
z=sortrows(x,1);
if threshold==0
labels=unique(z(:,1));%find unique values in z
else
K=linspace(0,1,threshold+1); K(1)=[];
labels=quantile(unique(z(:,1)),K)';
end
labels(end+1)=labels(end)+1;
ll=length(labels); %count unique value
a=zeros(ll,2); b=a; c=zeros(ll,1);%array preallocation
ubar=mean(x(x(:,2)==1),1); %unhealthy mean value
hbar=mean(x(x(:,2)==0),1); %healthy mean value
for K=1:ll
if hbar<ubar
TP=length(x(x(:,2)==1 & x(:,1)>labels(K)));
FP=length(x(x(:,2)==0 & x(:,1)>labels(K)));
FN=length(x(x(:,2)==1 & x(:,1)<=labels(K)));
TN=length(x(x(:,2)==0 & x(:,1)<=labels(K)));
else
TP=length(x(x(:,2)==1 & x(:,1)<labels(K)));
FP=length(x(x(:,2)==0 & x(:,1)<labels(K)));
FN=length(x(x(:,2)==1 & x(:,1)>=labels(K)));
TN=length(x(x(:,2)==0 & x(:,1)>=labels(K)));
end
M=[TP FP;FN TN];
a(K,:)=diag(M)'./sum(M); %Sensitivity and Specificity
b(K,:)=diag(M)./sum(M,2); %Positive and Negative predictivity
c(K)=trace(M)/sum(M(:)); %Efficiency
end
if hbar<ubar
xroc=flipud(1-a(:,2)); yroc=flipud(a(:,1)); %ROC points
labels=flipud(labels);
else
xroc=1-a(:,2); yroc=a(:,1); %ROC points
end
st=[1 mean(xroc) 1]; L=[0 0 0]; U=[Inf 1 Inf];
fo_ = fitoptions('method','NonlinearLeastSquares','Lower',L,'Upper',U,'Startpoint',st);
ft_ = fittype('1-1/((1+(x/C)^B)^E)',...
'dependent',{'y'},'independent',{'x'},...
'coefficients',{'B', 'C', 'E'});
cfit = fit(xroc,yroc,ft_,fo_);
xfit=linspace(0,1,500);
yfit=feval(cfit,xfit);
Area=trapz(xfit,yfit); %estimate the area under the curve
%standard error of area
Area2=Area^2; Q1=Area/(2-Area); Q2=2*Area2/(1+Area);
V=(Area*(1-Area)+(lu-1)*(Q1-Area2)+(lh-1)*(Q2-Area2))/(lu*lh);
Serror=realsqrt(V);
%confidence interval
ci=Area+[-1 1].*(realsqrt(2)*erfcinv(alpha)*Serror);
if ci(1)<0; ci(1)=0; end
if ci(2)>1; ci(2)=1; end
m=zeros(1,4);
if verbose
%z-test
SAUC=(Area-0.5)/Serror; %standardized area
p=1-0.5*erfc(-SAUC/realsqrt(2)); %p-value
%Performance of the classifier
if Area==1
str='Perfect test';
elseif Area>=0.90 && Area<1
str='Excellent test';
elseif Area>=0.80 && Area<0.90
str='Good test';
elseif Area>=0.70 && Area<0.80
str='Fair test';
elseif Area>=0.60 && Area<0.70
str='Poor test';
elseif Area>=0.50 && Area<0.60
str='Fail test';
else
str='Failed test - less than chance';
end
%display results
disp('ROC CURVE DATA')
disp(tr)
fprintf('Cut-off point\t\tSensivity\tSpecificity\tEfficiency\tPos. Pred.\tNeg. Pred.\n')
table=[labels'; a(:,1)'; a(:,2)';c'; b(:,1)'; b(:,2)';]';
fprintf('%0.4f\t\t%0.4f\t\t%0.4f\t\t%0.4f\t\t%0.4f\t\t%0.4f\n',table')
disp(tr)
disp(' ')
disp('ROC CURVE ANALYSIS')
disp(' ')
disp(tr)
str2=['AUC\t\t\tS.E.\t\t\t\t' num2str((1-alpha)*100) '%% C.I.\t\t\tComment\n'];
fprintf(str2)
disp(tr)
fprintf('%0.5f\t\t\t%0.5f\t\t\t%0.5f\t\t%0.5f\t\t\t%s\n',Area,Serror,ci,str)
disp(tr)
没有合适的资源?快使用搜索试试~ 我知道了~
一 基于Bp算法的人脸识别专题 pcabp kpcabp算法算法
共1663个文件
bmp:1600个
m:32个
mat:30个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 195 浏览量
2022-07-03
07:30:48
上传
评论
收藏 87.04MB RAR 举报
温馨提示
一 基于Bp算法的人脸识别专题 pcabp kpcabp算法算法
资源推荐
资源详情
资源评论
收起资源包目录
一 基于Bp算法的人脸识别专题 pcabp kpcabp算法算法 (1663个子文件)
s28_10.bmp 11KB
s5_3.bmp 11KB
s24_1.bmp 11KB
s21_4.bmp 11KB
s33_2.bmp 11KB
s29_4.bmp 11KB
s27_5.bmp 11KB
s22_2.bmp 11KB
s40_6.bmp 11KB
s33_5.bmp 11KB
s33_6.bmp 11KB
s5_10.bmp 11KB
s1_6.bmp 11KB
s2_4.bmp 11KB
s36_9.bmp 11KB
s27_6.bmp 11KB
s11_8.bmp 11KB
s27_1.bmp 11KB
s26_3.bmp 11KB
s35_8.bmp 11KB
s19_5.bmp 11KB
s30_3.bmp 11KB
s5_5.bmp 11KB
s32_7.bmp 11KB
s11_7.bmp 11KB
s27_2.bmp 11KB
s32_2.bmp 11KB
s36_3.bmp 11KB
s17_2.bmp 11KB
s25_4.bmp 11KB
s23_1.bmp 11KB
s20_1.bmp 11KB
s2_7.bmp 11KB
s32_5.bmp 11KB
s11_2.bmp 11KB
s5_4.bmp 11KB
s30_4.bmp 11KB
s33_9.bmp 11KB
s4_7.bmp 11KB
s27_4.bmp 11KB
s1_8.bmp 11KB
s19_4.bmp 11KB
s15_5.bmp 11KB
s29_3.bmp 11KB
s24_6.bmp 11KB
s25_1.bmp 11KB
s4_4.bmp 11KB
s36_5.bmp 11KB
s2_3.bmp 11KB
s19_6.bmp 11KB
s40_5.bmp 11KB
s6_10.bmp 11KB
s22_3.bmp 11KB
s39_5.bmp 11KB
s17_4.bmp 11KB
s11_9.bmp 11KB
s9_4.bmp 11KB
s28_5.bmp 11KB
s21_2.bmp 11KB
s37_2.bmp 11KB
s13_9.bmp 11KB
s3_1.bmp 11KB
s23_2.bmp 11KB
s12_4.bmp 11KB
s34_6.bmp 11KB
s38_8.bmp 11KB
s10_9.bmp 11KB
s1_10.bmp 11KB
s37_7.bmp 11KB
s18_2.bmp 11KB
s12_6.bmp 11KB
s35_2.bmp 11KB
s9_5.bmp 11KB
s22_4.bmp 11KB
s5_9.bmp 11KB
s13_2.bmp 11KB
s39_8.bmp 11KB
s19_10.bmp 11KB
s33_8.bmp 11KB
s14_6.bmp 11KB
s20_9.bmp 11KB
s39_2.bmp 11KB
s20_2.bmp 11KB
s26_1.bmp 11KB
s10_10.bmp 11KB
s32_4.bmp 11KB
s5_8.bmp 11KB
s20_5.bmp 11KB
s24_5.bmp 11KB
s36_1.bmp 11KB
s3_6.bmp 11KB
s11_4.bmp 11KB
s37_3.bmp 11KB
s26_10.bmp 11KB
s24_8.bmp 11KB
s37_5.bmp 11KB
s38_6.bmp 11KB
s34_1.bmp 11KB
s8_1.bmp 11KB
s12_8.bmp 11KB
共 1663 条
- 1
- 2
- 3
- 4
- 5
- 6
- 17
资源评论
人工智能专属驿站
- 粉丝: 282
- 资源: 174
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功