MATLAB Answers

0

How to use multiple labels as targets in Neural Net Pattern Recognition Toolbox?

Asked by Joyjit Chatterjee on 8 Dec 2018 at 22:48
Latest activity Commented on by Joyjit Chatterjee on 9 Dec 2018 at 13:05
I am trying to use the Neural Net Pattern Recognition toolbox in MATLAB for recognizing different types of classes in my dataset. I have a 21392 x 4 table, with the columns 1-3 which I would like to use as predictors and the 4th column has the labels with 14 different categories (strings like Angry, Sad, Happy, Neutral etc.). It seems that the Neural Net Pattern Recognition toolbox, unlike the MATLAB Classification Learner toolbox doesn't allow me to import the table and automatically extract the predictors and responses from it. Moreover, I am unable to either specify the inputs and targets to the neural network manually as it isn't showing up in the options.
I looked into the examples like the Iris Dataset, Wine Dataset, Cancer Dataset etc., but all of them only have 2-3 classes as outputs which are being Identified and the labels are not string type unlike mine like Angry, Sad, Happy, Neutral etc. (total 14 different classes). I would like to know how I can use my table as input to the neural network pattern recognition toolbox, or otherwise, any way in which I can extract the data from my table and use it in the toolbox. I am new to using the toolbox, so any help in this regard would be highly appreciated. Thanks!

  0 Comments

Sign in to comment.

1 Answer

Answer by Greg Heath
on 9 Dec 2018 at 6:55

The following is standard for classification and pattern recognition:
1. Label the classes from 1 to 14
2. Use the columns of the 14-dimensional unit matrix eye(14) as columns of the target matrix
HOWEVER, BEFORE YOU START WITH YOUR DATA, DO THE FOLLOWING
1. Consider the examples used in the documentation
help patternnet
and
doc patternnet
2. Consider some of my posts in BOTH ANSWERS and COMP.SOFT.SYS.MATLAB
greg patternnet
*THANK YOU FOR FORMALLY ACCEPTING MY ANSWER*
Greg

  1 Comment

Thanks for the answer. I went throughthe documentation on patternnet and am still confused with some queries:-
  1. doc patternnet documentation mentions "The target data for pattern recognition networks should consist of vectors of all zero values except for a 1 in element i, where i is the class they are to represent."
I am confused as to how I can label my classes from 1-14. Suppose I have extracted the labels column from the table I have (my_table), is this the right way to convert the labels column into target for neural net pattern recognition toolbox?
labels = my_table.labels;
my_matrix = eye(14);
targets = [];
for i = 1:size(labels,1)
if(labels(i) == "Class1")
targets(i) = my_matrix(1,:);
elseif(labels(i) == "Class2")
targets(i) = my_matrix(2,:);
elseif(labels(i) == "Class3")
targets(i) = my_matrix(3,:);
elseif(labels(i) == "Class4")
targets(i) = my_matrix(4,:);
elseif(labels(i) == "Class5")
targets(i) = my_matrix(5,:);
elseif(labels(i) == "Class6")
targets(i) = my_matrix(6,:);
elseif(labels(i) == "Class7")
targets(i) = my_matrix(7,:);
elseif(labels(i) == "Class8")
targets(i) = my_matrix(8,:);
elseif(labels(i) == "Class9")
targets(i) = my_matrix(9,:);
elseif(labels(i) == "Class10")
targets(i) = my_matrix(10,:);
elseif(labels(i) == "Class11")
targets(i) = my_matrix(11,:);
elseif(labels(i) == "Class12")
targets(i) = my_matrix(12,:);
elseif(labels(i) == "Class13")
targets(i) = my_matrix(13,:);
elseif(labels(i) == "Class14")
targets(i) = my_matrix(14,:);
end
end
2. In the example for patternet in the documentation code:-
[x,t] = iris_dataset;
net = patternnet(10);
net = train(net,x,t);
view(net)
y = net(x);
perf = perform(net,t,y);
classes = vec2ind(y);
I can see the the iris_dataset is loaded into irisInputs and irisTargets. So in my case, is there a role of classes = vec2ind(y)? vec2end() transforms vectors to indices as per the documentation, so how I can actually use it for my problem? It would be helpful if you can help with a sample syntax so I can understand it better. Many thanks and Cheers.

Sign in to comment.