How to interpret the outputs of patternnet?

15 views (last 30 days)
afef
afef on 30 Jun 2017
Commented: Greg Heath on 2 Jul 2017
I created a neural network for classification and when i wanted to test it with new inputs the outputs was not like the target values 0 or 1 when i was looking for this i found that the outputs can be interpreted to be class posterior probability estimates, conditional on the input is this the problem ? or it can be because i don't get accuracy > 90% but i reach 71,9% ?
this is the code that i used :
rng(0); % initialize the RNG to the same state before training to obtain reproducibility
inputs = patientInputs;
targets = patientTargets;
N=981
I=9
O=2
[ I N ] = size(inputs)
[ O N ] = size(targets)
[x,ps] = mapminmax(inputs);
t=targets;
trainFcn = 'trainbr';
% Create a Pattern Recognition Network
hiddenLayerSize =8;
net = patternnet(hiddenLayerSize,trainFcn);
net.inputs{1}.processFcns = {'removeconstantrows','mapminmax'};
net.outputs{2}.processFcns = {'removeconstantrows','mapminmax'};
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;
net.performFcn = 'mse';
net.trainParam.max_fail=6;
% Choose Plot Functions
% For a list of all plot functions type: help nnplot
net.plotFcns = {'plotperform','plottrainstate','ploterrhist', ...
'plotconfusion', 'plotroc'};
% Train the Network
net= configure(net,x,t); %remove previous weights and reinitialize with random weights.
[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);
% 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
view(net)
And this is the confusion mmatrix that i got

Answers (1)

Greg Heath
Greg Heath on 1 Jul 2017
Edited: Greg Heath on 1 Jul 2017
You are confused (;>).
1. The original data set is divided into trn/val/tst subsets and yields 4 confusion matrices.
2. NEW DATA is TEST DATA and IS NOT DIVIDED. Therefore, there is only ONE CONFUSION MATRIX.
3. Your new data probably doesn't have the same summary statistics as your original data. That is why performance is so poor.
ADDITIONALLY
4. You did not round your outputs to obtain 0-1 outputs and obtain count confusion matrices (In addition to the per cent confusion matrices)
5. You can also include unit sum prior probabilities and class conditional costs to use prior information to influence the classification. These are explained in most classification text books and my posts in the comp.ai.neural-nets Newsgroup.
Hope this helps
Thank you for formally accepting my answer
Greg
  2 Comments
Greg Heath
Greg Heath on 2 Jul 2017
Search ANSWERS using
greg round
The first post
Interpreting neural network result Asked by Bushra on 23 Jun 2012
looks relevant.
I haven't checked the other 153 posts.
Greg

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by