How to display Confusion matrix of Testing ,Training and Validation without using nprtool

Hello Everyone ,
I want to display confusion matrix of Testing , Training and validation through code .
plotConfusion(Target, Output) only displays the overall confusion matrix .
i can only show the three matrices first time i train the network using newpr. How to display them again ?

 Accepted Answer

net = patternnet(x,t,H); [net tr ] = train(net,x,t);
The training record in the structure tr contains the indices for the trn/val/tst subsets.
Therefore, they can be used to obtain separate performance results.
Hope this helps.
Greg

3 Comments

Thank You Greg !
This was really helpful , but i'm still unable to get the same confusion matrix .
Here is my code after you suggestion :
one thing more i'm using Matlab 7.9 , so it doesn't have patternet function .
for i = 1:540 % 540 is total number of input samples
for j = 1:324 % 324 is number of samples used only for training ,remaining 108 for testing & 108 validat
if(i==tr.trainInd(1,j))
trainOut(:,k)=output(:,tr.trainInd(1,j)); % output = sim(net,input)
% Here we are taking corresponding output values of the training indices.
k=k+1;
end
end
end
%.Similarly i got corresponding Target values using the same code above with a little change
for i = 1:540
for j = 1:324
if(i==tr.trainInd(1,j))
trainTar(:,k)=Tar(:,tr.trainInd(1,j)); % getting corresponding target values
k=k+1;
end
end
end
% Then i plot confusion matrix for Training Data only
plotconfusion(trainTar,trainOut)
% x = inputs, t = targets, y = outputs
% Train the Network
[net, tr] = train(net, x, t);
% Training Confusion Plot Variables
yTrn = net(x(:,tr.trainInd));
tTrn = t(:,tr.trainInd);
% Validation Confusion Plot Variables
yVal = net(x(:,tr.valInd));
tVal = t(:,tr.valInd);
% Test Confusion Plot Variables
yTst = net(x(:,tr.testInd));
tTst = t(:,tr.testInd);
% Overall Confusion Plot Variables
yAll = net(x);
tAll = t;
% Plot Confusion
plotconfusion(tTrn, yTrn, 'Training', tVal, yVal, 'Validation', tTst, yTst, 'Test', tAll, yAll, 'Overall')
yTst = net(x(:,tr.testInd)) when i use this command, i get an error. Subscript indices must either be real positive integers or logicals.

Sign in to comment.

More Answers (0)

Categories

Find more on Deep Learning Toolbox in Help Center and File Exchange

Asked:

on 18 Jun 2012

Commented:

on 6 Aug 2015

Community Treasure Hunt

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

Start Hunting!