error using [c,cm,ind,per] = confusion(targets,outputs)
2 views (last 30 days)
Show older comments
Serious newbie attempting to tease out the false and true positives and false and true negatives from a dataset using cross-fold validation. My code runs fine and gives me the GUI displays of the results, but I want the actual data from the confusion matrix too because I want to run the training several times to get a good average so I can report on / discuss differences in accuracy for the 4 categories. That line ([c,cm,ind,per] = confusion(train_outputs,y) in the code below) isn't working. I just get an error that my matrices are mismatched. I know this is just simple for others but it has me stumped.
I'm about to resort to running it multiple times, opening the confusion matrix GUI representation each time and type in the figures into my excel spreadsheet. Problem is I have at least 5 more datasets I need to do this for, and I'd rather understand this than do a kludge. Before I resort to plan B, perhaps someone out there can see what I've done wrong in my script and suggest a fix?
echo on
% data file 'ann_09_samples_75x.csv' is a 4x75 matrix
inputs = csvread('ann_09_samples_75x.csv')
% data file 'ann_09_targets_75x.csv' is a 1x75 matrix
outputs = csvread('ann_09_targets_75x.csv')
%cvpartition creates a set of partitions that encompass all the data, not just perpetually random like the Wizard creates
CVO = cvpartition(outputs(1,:),'k',10)
%NumTestSets is equal to the number of total test sets partitioned, which is 10
err = zeros(CVO.NumTestSets,1);
%following loop runs through each of the partitioned sets
for i = 1:CVO.NumTestSets
trIdx = CVO.training(i);
teIdx = CVO.test(i);
train_inputs= inputs(:,trIdx);
train_outputs= outputs(:,trIdx);
test_inputs= inputs(:,teIdx);
test_outputs= outputs(:,teIdx);
net = patternnet(10);
net = train(net, train_inputs, train_outputs);
y = net(test_inputs);
[c,cm,ind,per] = confusion(train_outputs,y)
err(i) = sum(round(y)==test_outputs)/length(test_outputs);
end
all_err = sum(err)/CVO.NumTestSets
sdev = std(err)
echo off
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!