how do create test label?

hai...i tried to run the kNN matlab code;
function [acc,score]=kNN(train,trainlabel,test,testlabel,k)
%train,trainlabel,test,testlabel
%return "accuravy rate"
N_tr=size(train,1);
N_ts=size(test,1);
Answer=zeros(N_ts,1);
for i=1:N_ts
% calc distance^2 between all train data and a test data
Temp=train-ones(N_tr,1)*test(i,:);
Distance2=sum(Temp.^2,2);
% [MIN I]=min(Distance2);
% Answer(i)=trainlabel(I);
neibors=sortrows([Distance2,trainlabel],1);
Answer(i)=mode(neibors(1:min(k,size(neibors,1)),2));
end
%[ANS testlabel];
acc=(1-nnz(Answer-testlabel)/N_ts)*100;
score=(Answer-testlabel==0);
how do i create the train label?(please see my 'DATA.txt' attachment).
my DATA.txt contains 5 X 10 matrix. each row represent class1~class5.

回答(0 个)

类别

在 帮助中心 和 File Exchange 中查找有关 Statistics and Machine Learning Toolbox 的更多信息

标签

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by