Dear all,
Thank you in advance for your help.
I have prepared the following script in order to train a NN and then use it for forecasting.
trainFcn = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = 3; net = fitnet(hiddenLayerSize,trainFcn); net.input.processFcns = {'removeconstantrows','mapminmax'}; net.output.processFcns = {'removeconstantrows','mapminmax'}; net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 70/100; net.divideParam.valRatio = 15/100; net.divideParam.testRatio = 15/100; net.performFcn = 'mse'; % Mean Squared Error
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ... 'plotregression', 'plotfit'}; % Train the Network
[net,tr] = train(net,x,t); % Test the Network
y = net(x); e = gsubtract(t,y); performance = perform(net,t,y) % Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1}; valTargets = t .* tr.valMask{1}; testTargets = t .* tr.testMask{1}; trainPerformance = perform(net,trainTargets,y) valPerformance = perform(net,valTargets,y) testPerformance = perform(net,testTargets,y) % Forecast
fv = net(xv);
- Each time I run the script I get the NN is retrained and produces different results (similarly to pressing the retrain button in the GUI).
- Each time the training is very good with test and validation performance between 0.025-0.035 however when I use the NN to forecast the out-of-sample data I get completely different results. For example the Mean Absolute Error can be between 10%-25% while the times the absolute error is less than 20% is between 60%-86%.
- If I clear the memory I get the same results (and if I clear and then keep executing the script I get the same results in the same order).
I can imagine that this is due to local minima and the split of the training/validation and test data. Is that correct?
And the second question is which NN do I keep since all of them in-sample perform very well and similarly (comparing the performance criteria, MSE and R^2) ?
Any suggestion in order to improve the methodology and/or stabilising the results?
Best Answer