How can we Convert Target Labels for Multiclass Output in a Neural Network?

1.3k Views Asked by At

Please someone give me a clear idea about my stack:

For reference, see the previous question made by someone else (https://stackoverflow.com/questions/19593362/ann-multiple-vs-single-outputs) about the multiclass output case.

I am trying to classify data as one of A, B, C, and D.

In an answer given to the question above, it is suggested that we can train our network on labeled data, but convert all "A" labels to [1 0 0 0], all "B" labels to [0 1 0 0], "C" labels to [0 0 1 0], and "D" labels to [0 0 0 1]. (This is called a "one-hot" encoding.).

My question is: how can we convert these target labels in MATLAB code? (Our output target is in this case one-hot coding as explained above.)

Let's say, for example:

 data= xlsread ('disease');
 input  = data (1:75,1:10);
 target = data (1:75, 11);

How can we define this target to be those labels??

Many thanks in advance.

1

There are 1 best solutions below

1
On

if target is a column vector of strings of length m , and diseases is a row vector of labels of length n, then you can create a logical array classlabels of size(m,n) using the code below.

classlabels = (target==diseases)