MATLAB: Different neural network training result each time

data division tutorialgeh: good threadneural network

Hey
I am trying to implement a neural network with leave-one-out crossvalidation. The problem is when I train the network I get a different result each time.
My code is:
——-
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);
net.divideFcn = '';
[net] = train(net,inputs,targets);
testOut = net(validation);
[c,cm] = confusion(validationTarget,testOut); %cm
TP = cm(1,1); FN = cm(1,2); TN = cm(2,2); FP = cm(2,1);
fprintf('Sensitivity : %f%%\n', TP/(TP+FN)*100);
fprintf('Specificity : %f%%\n\n', TN/(TN+FP)*100);
———–
Is it because train() uses different proportions of the input data each time? In this case I have tried to avoid dividing data in training, validation and test by setting net.divideFcn = ''. I have also tried to set net.divideParam.trainRatio = 100/100.
I have tried to set EW = 1, but it does not change anything.
Any suggestions?
Morten

Best Answer

Try to add this command on the beginning of a script:
RandStream.setDefaultStream(RandStream('mt19937ar','seed',1));