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

6 次查看(过去 30 天)
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!

回答(2 个)

Greg Heath
Greg Heath 2018-12-9
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 个评论
Joyjit Chatterjee
Joyjit Chatterjee 2018-12-9
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.

请先登录,再进行评论。


RAJA SEKHAR BATTU
RAJA SEKHAR BATTU 2022-10-17
编辑:RAJA SEKHAR BATTU 2022-10-27
I think I am very late to answer this question. But, I want to share the procedure I followed for my problem.
lets say we have 2000*3 matrix as input rows represent data for 10 classes with 200 each. coloumns represent features selected.
I think we can start with
first class second class third class ..............repeat for 10 classes
1 1 1 1 1 1 .....first(200) 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 1 1 1 1 1 1 .....next(200) 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 1 1 1 1 1 1 .....next(200)
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
0 0 0 0 0 0....... 0 0 0 0 0 0....... 0 0 0 0 0 0.......
This is the way of labelling(target matrix) the input matrix.
create two seprate matrices input and target. And also create a matlab script which can make the problem easy.
After labelling transpose this matrix for your case..
Thank you
Raja

产品


版本

R2018a

Community Treasure Hunt

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

Start Hunting!

Translated by