Azzera filtri
Azzera filtri

How to choose the number of neurons in the hidden layer of neural network?

4 visualizzazioni (ultimi 30 giorni)
Hi, i'm using the neural network for classification using nnstart and i have dataset (input) with a size of 9*981 and i want to know how to choose the number of neurons in the hidden layer for it ?

Risposta accettata

Greg Heath
Greg Heath il 5 Giu 2017
Use trial and error with the training subset goal
MSEtrngoal = 0.01*var(trntarget,1) % 1-D target
or
MSEtrngoal = 0.01*mean(var(trntarget',1)) % Otherwise
Start with the MATLAB default H = 10 and design ~10 nets for each setting of H. Each of the 10 is initialized with a different setting of random initial weights.
Hope this helps
Thank you for formally accepting my answer
Greg
  2 Commenti
afef
afef il 5 Giu 2017
This is the script that i got after using nnstart
x = inputpatient';
t = targetpatient';
% Choose a Training Function
% For a list of all training functions type: help nntrain
% 'trainlm' is usually fastest.
% 'trainbr' takes longer but may be better for challenging problems.
% 'trainscg' uses less memory. Suitable in low memory situations.
trainFcn = 'trainscg'; % Scaled conjugate gradient backpropagation.
% Create a Pattern Recognition Network
hiddenLayerSize = 10;
net = patternnet(hiddenLayerSize);
% Setup Division of Data for Training, Validation, Testing
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
% View the Network
view(net)
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
%figure, plotconfusion(t,y)
%figure, plotroc(t,y)
and i tried to change the hiddenLayerSize to improve the accuracy of the network and i got this confusion matrix
And i still can't achieve the good accuracy . So what can i do please ?
afef
afef il 6 Giu 2017
https://www.mathworks.com/matlabcentral/answers/343156-how-to-choose-the-number-of-neurons-in-the-hidden-layer-of-neural-network#answer_269569
Dear Greg Heath sorry but i don't where should i add the code for trial and error that you told me to add in my script and you mean by default H = 10 the number of neurons in the hidden layer??? I really will appreciate if you answer me .

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Sequence and Numeric Feature Data Workflows in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by