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

2 次查看(过去 30 天)
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 ?

采纳的回答

Greg Heath
Greg Heath 2017-6-5
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 个评论
afef
afef 2017-6-5
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 2017-6-6
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 .

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Sequence and Numeric Feature Data Workflows 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by