test_error.m
来自「RBF神经网络 RBF神经网络」· M 代码 · 共 29 行
M
29 行
function [TestErrorMSE,TestErrorRate]=Test_Error(test_p,test_t,cents,W,R)
% 求测试MSE及测试分类错误率
row=size(test_p,1);
for m=1:row
for n=1:size(cents,1)
H2(m,n)=exp(-(test_p(m,:)-cents(n,:))*R(:,:,n)*(test_p(m,:)-cents(n,:))');
end
end
h(1:row)=1;
H2=[h',H2];
t=H2*W;
% 求MSE
t_error=t-test_t;
t_error=t_error.^2;
% t_error=abs(t_error);
t_error=sum(sum(t_error,2)/size(test_t,2));
TestErrorMSE=t_error/row;
% 求测试分类错误率
[t1,index1]=max(t,[],2);
[t2,index2]=max(test_t,[],2);
TestCorrectnum=0;
for i=1:row
if index1(i,1)==index2(i,1)
TestCorrectnum=TestCorrectnum+1;
end
end
TestErrorRate=1-TestCorrectnum/row;
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?