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)
-----------------------------
Best Answer