Bad accuracy in the confusion matrix of neural network

9 views (last 30 days)
Hi,i tried to create neural network for classification using nprtool i used the advanced script so i could normalize my data but in my cofusion matrix the accuracy is not that good.Tis is my code :
x =patientInputs;
t = patientTargets;
setdemorandstream (391418381)
trainFcn = 'trainscg';
hiddenLayerSize = 24;
net = patternnet(hiddenLayerSize);
net.input.processFcns = {'removeconstantrows','mapminmax'};
net.output.processFcns = {'removeconstantrows','mapminmax'};
net.divideFcn = 'dividerand';
net.divideMode = 'sample';
net.divideParam.trainRatio = 70/100;
net.divideParam.valRatio = 15/100;
net.divideParam.testRatio = 15/100;
net.performFcn = 'crossentropy';
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotconfusion', 'plotroc'};
[net,tr] = train(net,x,t);
y = net(x);
e = gsubtract(t,y);
performance = perform(net,t,y)
tind = vec2ind(t);
yind = vec2ind(y);
percentErrors = sum(tind ~= yind)/numel(tind);
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)
And this is the confusion matrix that i got
Please can anyone help me what should i modify in my code to improve the accuracy of my neural network ?

Answers (1)

orlem lima dos santos
orlem lima dos santos on 9 Jan 2018
Edited: orlem lima dos santos on 9 Jan 2018
Hi, to obtain a better accuracy what I recommend to you is find the best hyperparameters (numbers node in the hidden layer, epochs and so on) of your network in order to do this you could go try and error or use algorithms like gridsearch (best option)
This algorithm is going to give you the best hyperparameters given the inputs and targets.


Find more on Sequence and Numeric Feature Data Workflows in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by