Could you please help me in Artificial neural network - supervised learning?
Ältere Kommentare anzeigen
Artificial neural network
I have a data set and I like to know the best NN topology to use (# of hidden layers and # of nodes – currently I am using [30 50 30]). I have about 1000 samples with 20 input variables and one output.
I learned using the following code; but my test(with new data set-never seen by ANN) didn’t give me desirable output. Could your please varify my method?
%load data
inputs_bn, targets_bn;
%Normalize - Do i have to normalize the data?
[inputs,ps] = mapminmax(inputs_bn);
[targets,ts] = mapminmax(targets_bn);
HL=[30 50 30];
%inputs
%targets
% Create a Fitting Network
hiddenLayerSize = HL;
net=fitnet(hiddenLayerSize,'traingdx'); % Is this used for predictions?
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivide
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.trainFcn = 'trainlm'; % Levenberg-Marquardt
net.trainParam.min_grad=1e-8;
% Choose a Performance Function
%change from
%net.performFcn = 'mse'; % Mean squared error
%change from
%change to
net.performFcn='msereg';
net.performParam.ratio=0.5;
%change to
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
% Train the Network
[net,tr] = train(net,inputs,targets,'useParallel','yes','showResources','yes'); %trainr gave bad results
% Test the Network
outputs11 = net(inputs);
outputs=mapminmax('reverse',outputs11,ts);
errors = gsubtract(targets,outputs);
performance = perform(net,targets,outputs)
% Recalculate Training, Validation and Test Performance
trainTargets = targets .* tr.trainMask{1};
valTargets = targets .* tr.valMask{1};
testTargets = targets .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,outputs)
valPerformance = perform(net,valTargets,outputs)
testPerformance = perform(net,testTargets,outputs)
% View the Network
%view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure(1), plotfit(net,inputs,targets)
%figure, plotregression(targets,outputs)
figure(111), ploterrhist(errors)
%%%%%%%%
%%%%Load Test DATA
% Target_output
outputs_Test = sim(net,input_Test);
outputs_Test=mapminmax('reverse',ooutputs_Test,ts);
errors = outputs_Test - Target_output;
plot(errors)
Thanks!
Jude
Akzeptierte Antwort
Weitere Antworten (2)
Jude Alexander
am 30 Okt. 2015
0 Stimmen
Jude Alexander
am 3 Nov. 2015
0 Stimmen
2 Kommentare
Greg Heath
am 5 Nov. 2015
Comment by Jude Alexander that was ERRONEOUSLY posted in an ANSWER box.
Hi Greg, Thank you for all your help. My error (net estimate - target) is high on the low and high end of the boundaries. Is there any way to improve it?
I am using:
net.trainFcn = 'trainbr';
net.layers{1}.transferFcn = 'satlin';
I am following this example to reduce the over fitting
(% http://www.mathworks.com/help/nnet/ug/improve-neural-network-generalization-and-avoid-overfitting.html)
Thanks.
Jude
Greg Heath
am 5 Nov. 2015
There is no reason to use the non-default functions TRAINBR and SATLIN.
1. FITNET with H < Hub prevents over-fitting and the default 0.7/0.15/0.15 data division validation set prevents overtraining.
2. SATLIN (What is your output transfer function?)is not as powerful as the default TANSIG/PURELIN combination.
3. If you post your data I will take a look at it. Use *.m or *.txt
Kategorien
Mehr zu Analysis of Variance and Covariance finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!