MATLAB Answers

How to improve the accuracy of neural networks (feed forward network)

44 views (last 30 days)
CHRISTEENA JOSE on 29 Nov 2020
Commented: Madhav Thakker on 21 Dec 2020
Hello Everyone!
I created neural network using nftool and i want to increase accuracy of my network. I edited the script automatically generated by the nftool app. How to change adaptation learning function in this code? How to change performance function in this script. I changed the performance function to 'mse' to 'mae' but its giving an error message. Here is the script for my network. And also suggest other methods to improve accuracy of network?
% Solve an Input-Output Fitting problem with a Neural Network
% Script generated by Neural Fitting app
% Created 27-Nov-2020 09:34:39
% This script assumes these variables are defined:
% x - input data.
% y - target data.
close all;
[num,~,~] = xlsread('TrainingNN_3.xlsx');
x = num(1:72,2:6);
y = num(1:72,7:9);
x = x';
t = y';
% 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 = 'trainlm'; % Levenberg-Marquardt backpropagation.
% Create a Fitting Network
hiddenLayerSize = [25 15];
net = fitnet(hiddenLayerSize,trainFcn);
net.layers{1}.transferFcn = 'tansig';
net.layers{2}.transferFcn = 'tansig';
net.layers{3}.transferFcn = 'tansig';
% Choose Input and Output Pre/Post-Processing Functions
% For a list of all processing functions type: help nnprocess
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.output.processFcns = {'removeconstantrows','mapminmax'};
% Setup Division of Data for Training, Validation, Testing
% For a list of all data division functions type: help nndivision
net.divideFcn = 'dividerand'; % Divide data randomly
net.divideMode = 'sample'; % Divide up every sample
net.divideParam.trainRatio = 90/100;
net.divideParam.valRatio = 5/100;
net.divideParam.testRatio = 5/100;
% Choose a Performance Function
% For a list of all performance functions type: help nnperformance
net.performFcn = 'mse'; % Mean Squared Error
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotregression', 'plotfit'};
% changing trainParam
net.trainParam.epochs = 10000;
net.trainParam.max_fail =10;
net.trainParam.min_grad = 1e-09;
% Train the Network
[net,tr] = train(net,x,t);
% Test the Network
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
% Recalculate Training, Validation and Test Performance
trainTargets = t .* tr.trainMask{1};
valTargets = t .* tr.valMask{1};
testTargets = t .* tr.testMask{1};
trainPerformance = perform(net,trainTargets,y)
valPerformance = perform(net,valTargets,y)
testPerformance = perform(net,testTargets,y)
% View the Network
% Plots
% Uncomment these lines to enable various plots.
%figure, plotperform(tr)
%figure, plottrainstate(tr)
%figure, ploterrhist(e)
figure, plotregression(t,y)
%figure, plotfit(net,x,t)
% Deployment
% Change the (false) values to (true) to enable the following code blocks.
% See the help for each generation function for more information.
if (false)
% Generate MATLAB function for neural network for application
% deployment in MATLAB scripts or with MATLAB Compiler and Builder
% tools, or simply to examine the calculations your trained neural
% network performs.
y = myNeuralNetworkFunction(x);
if (false)
% Generate a matrix-only MATLAB function for neural network code
% generation with MATLAB Coder tools.
y = myNeuralNetworkFunction(x);
if (false)
% Generate a Simulink diagram for simulation or deployment with.
% Simulink Coder tools.
  1 Comment
Madhav Thakker
Madhav Thakker on 21 Dec 2020
Hi Christeena,
What error did you get when using 'mae' performance function?

Sign in to comment.

Answers (1)

Jack Xiao
Jack Xiao on 2 Dec 2020
what is nftool ? is it in one matlab toolbox? why not directly use deep learning toolbox..

Community Treasure Hunt

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

Start Hunting!

Translated by