Data Division in MATLAB Neural Network Train Command

3.7k views Asked by At

While training a neural network in MATLAB I am using "train" command. Is this command auto divide the data into training, testing, and validation sets or we have to divide the data manually.

1

There are 1 answers

2
AVK On

Yes, it does. But we can divide the data manually, if we want to. net.divideFcn and net.divideParam fields of the net object should be used:

t=0:0.05:8; x= sin(t);
net = feedforwardnet(3);
net.divideFcn= 'dividerand'; % divide the data randomly 
net.divideParam.trainRatio= 0.7; % we use 70% of the data for training 
net.divideParam.valRatio= 0.3; % 30% is for validation
net.divideParam.testRatio= 0; % 0% for testing
net = train(net,t,x);
plot(t,x,t,net(t));

Here is an example of a manual data division:

net.divideFcn= 'divideind'; % divide the data manually
net.divideParam.trainInd= 1:100; % training data indices 
net.divideParam.valInd= 101:140; % validation data indices 
net.divideParam.testInd= 141:161;  % testing data indices