How to unable data division in net training?

1 次查看(过去 30 天)
I want to classify 11 different hand motions using patternnet and validate the result using 10-fold cross validation (9 for train and 1 for test). How can I unable data division in the training process? Is it ok to do that? My code is as follow:
load FeatureSet;
p=input; %[16 by 1342 ]
t=target; %[11 by 1342]
Nk=1342/11;
labels=[ones(Nk,1); 2.*ones(Nk,1); 3.*ones(Nk,1); 4.*ones(Nk,1); 5.*ones(Nk,1); 6.*ones(Nk,1); 7.*ones(Nk,1); 8.*ones(Nk,1); 9.*ones(Nk,1); 10.*ones(Nk,1); 11.*ones(Nk,1)];
kfold=10;
indices = crossvalind('Kfold',labels,kfold);
for i = 1:kfold
ts = (indices == i); tr = ~ts;
Ptr = p(tr,:); Pts = p(ts,:);
Ttr=t(tr,:); Tts = t(ts,:);
trainFcn = 'trainbr';
net = patternnet([32 32], trainFcn);
net.layers{1}.transferFcn = 'tansig'; % hidden layer 1
net.layers{2}.transferFcn = 'tansig'; % hidden layer 2
% %------------------------parameter
net.trainParam.lr = 0.1; %learning rate
net.trainParam.mc = 0.1; %momentum
%------------------------ train
[net,tr]= train(net,Ptr,Ttr);
%------------------------ test
outputs= sim(net,Pts);
[c,cm] = confusion(Tts,outputs);
pct(i)=100*(1-c); %correction rate
end

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Dimensionality Reduction and Feature Extraction 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by