How i can to choose a good structure of neural networks( number of nodes in hidden layer)
5 次查看(过去 30 天)
显示 更早的评论
I’am new to neural networks (for prediction) and I'm not sure how to go about trying to achieve better test error on my dataset. i have 1200*7 inputs matrix ( 1200 lines and 7 columns)and targets (1200*7) for training my neural network. I tested my neural network by differents datasets (not using in trianing). i got bad MSE about 0,10084 with 19 nodes in hidden layer!!!!. Always My program displays the following error message :
Error using .* Matrix dimensions must agree.
Error in neuralNetworktest (line 95) traintargetsTesting = targetsTesting .*tr.trainMask{1};
please advise my about this problem. thanks .
- * * this is my program : * * *
clear all
A = load('C:\Users\Omar\Desktop\les données\inputs.txt');
B = load('C:\Users\Omar\Desktop\les données\targets.txt');
C= load('C:\Users\Omar\Desktop\les données\inputs_Testing.txt');
D= load('C:\Users\Omar\Desktop\les données\targets_Testing.txt');
inputs = A';
targets = B';
inputs_Testing=C';
targets_Testing=D';
% Create a Fitting Network
% 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;
% For help on training function 'trainlm' type: help trainlm
% For a list of all training functions type: help nntrain
net.trainF = 'trainlm'; % Levenberg-Marquardt
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse' % Mean squared error
n=10;% number of iteration
fileoutmse=fopen('mse.xls','w');% open XLS file to save MSE and number of nodes
fprintf(fileoutmse,'%s\t%s\n','numnodes','MSE');
for NNHL=1:20 % NNHL number of nodes
fprintf('number of nodes in hidden layer :%d\n',NNHL);
net = fitnet(NNHL);
for j=1:n % n= number of iteration
[net,tr] = train(net,inputs,targets);
outputs = net(inputs_Testing);
perf = mse(net,targets_Testing,outputs);
fprintf(fileoutmse,'%d\t %.5f\r\n',NNHL,perf);
end
end
fclose(fileoutmse);
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
% Train the Network
% Test the Network
errors = gsubtract(targets_Testing,outputs);
performance = perform(net,targets_Testing,outputs)
% Recalculate Training, Validation and Test Performance
traintargets_Testing = targets_Testing .*tr.trainMask{1};
valtargets_Testing = targets_Testing .*tr.valMask{1};
testtargets_Testing = targets_Testing .*tr.testMask{1};
trainPerformance = perform(net,targets_Testing,outputs)
valPerformance = perform(net,valtargets_Testing,outputs);
testPerformance = perform(net,testtargets_Testing,outputs);
% View the Network
view(net)
fileout=fopen('outputs.xls','w'); % open Excel file to save outputs
fprintf(fileout,'%.2f\r\n',outputs);
fclose(fileout);
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, plotfit(net,inputs,targets)
%figure, plotregression(targets,outputs)
%figure, ploterrhist(errors)
-----------------------------
0 个评论
采纳的回答
Greg Heath
2014-5-19
[ I N ] = size(input) % [7 1200]
[ O N ] = size(target) % [ 7 1200 ]
Ntrn = N -2*(0.15*N) % 840
Ntrneq = Ntrn*O % 5880
Nw = (I+1)*H+(H+1)*O % 8*19+20*7=152+140 = 292
Since Ntrneq >> Nw, choose
MSEgoal << mean(var(target',1))
MSE ~ 0.1 is not bad if the RHS >~ 10
For details see my posts
greg fitnet MSEgoal
5 个评论
Greg Heath
2014-6-20
1. Please don't put comments and/or questions comments in the ANSWERS box. Use the COMMENT box.
% Thank you sir Greg Heath, i don't understand what's means these % commands??? : % % MSE00 = mean(var(target',1)) espcially Var !!!! % MSE00a = mean(var(target',0))
help var
doc var
They are reference MSEs obtained when the output is, NAIVELY, assumed to be a constant, independent of the input:
y00 = repmat(mean(target,2),1,N);
% and here normally: Ntrneq = N*O why in this line >>> Ntrneq = Ntrn*1
%where: Ntrn = N -2*(0.15*N)
Well, gee!! What could that possibly mean??? ( O = 1?)
% [ I N ] = [ 7 1200 ] [ O N ] = [ 1 1200 ]
% Ntrn = N -2*(0.15*N) % 840 Ntrneq = Ntrn*1 % 840
%
% anohter question please it is necessary to reset the weight during
% aprrentissage??!!
I don't know that word.
% And how i can do?? (to reset the weight of neural neutwork each iteration).
help configure
doc configure
Quite a few of these questions have been answered by me in the past. In the future, before asking a question, please make a search using
greg searchword
Thanks,
Greg
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Get Started with Statistics and Machine Learning Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!