📄 test_error.m
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -