Cross Validation in Neural Network ?

3 views (last 30 days)
Narges Sedre
Narges Sedre on 4 Dec 2018
Answered: Greg Heath on 5 Dec 2018
i want to do a cross validation 10% of the data should be for training and the rest is for test .
i dont know how to perform that.
filename='FIFA7.xlsx';
A =xlsread(filename);
[m,n]=size(A);
T= A(:,1);
data= A(:,(2:end));
rows80=int32(floor(0.8 * m));
trainingset=A(1:rows80,:);
testset=A(rows80+1:end,:);
t=trainingset(1:rows80,1);
t_test=A(rows80+1:end,1);
% k=10
% cvFols=crossvalind('kfold',l,k);
% for i =1:k
% testIdx=(cvFolds==i);
% trainIdx=~test;
%
%
net= newff(trainingset',t');
y=sim(net,trainingset');
%net.trainParam.epoch=20;
net= train(net,trainingset',t');
y=sim(net,trainingset');
y_test=sim(net,testset');
p=0;
y1=hardlim(y');
y2= hardlims(y_test);
for(i=1:size(t,1))
if(t(i,:)==y1(i,:))
p=p+1;
end
end
trainerror =100*p/size(trainingset,1);
e=0;
y2=hardlim(y_test');
for(j=1:size(t_test,1))
if(t_test(j,:)==y2(j,:))
e=e+1;
end
end
testerror=100*e/size(t_test,1)

Answers (1)

Greg Heath
Greg Heath on 5 Dec 2018
You may be confused. The MATLAB DEFAULT is RANDOM DATA DIVISION with
80% training
10% validation (tends to prevent overtraining)
10% testing
Depending om the size of the data, you can obtain 10 to 20 separate designs and choose the best.
Instead of storing all of the weights, I just store the current best net as I loop through the designs.
I am sure that I have posted zillions of examples in both the NEWSGROUP comp.soft.sys.matlab and ANSWERS.
Hope this helps.
Thank you for formally accepting my answer
Greg

Categories

Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!