Reputation: 492
I am new in using matlab nn library. I am looking for 2 class, binary classification. As in documentation, I have trained the network. The codeoutputs = net(inputs)
does not give me the class labels but instead it gives me some floating point numbers. How can I get the class label results so that I can use it in my grid search for optimizing the parameter? I am using 10 fold cross validation.
Upvotes: 1
Views: 837
Reputation: 104545
The traditional way to do this with neural networks when performing classification is to do this with one-hot encoding. To facilitate one-hot encoding, you examine whichever neuron gave you the largest response. Whatever neuron gave you the largest response is the associated class label you would choose. For example in your two neuron network, if neuron 1 gave you a response of 0.64 while neuron 2 gave you a response of 0.36, the input that you supplied to the neural network would be classified as label 1 as neuron 1 gave you the highest response.
Note that in the Neural Network toolbox, each example is in a column while each feature is in a row between layers. Therefore for the output layer, the outputs of the first neuron are in the first row and the outputs of the second neuron are in the second row.
To facilitate finding the classes, I will assume you are using the command-line functions instead of the GUI as it will make it easier: https://www.mathworks.com/help/nnet/gs/classify-patterns-with-a-neural-network.html#f9-26645. If you follow the tutorial, you should have a neural network called net
in your workspace. Simply forward the examples through the network, then choose the largest of each row along all of the columns to determine what the class of each example is.
Assuming your training, validation or testing data is stored in a variable called inputs
, your code would simply be this:
outputs = net(inputs);
[~, classes] = max(outputs, 1);
classes
would be a 1 x N
array where N
is the total number of examples you submitted into the network which would contain the classes of each example you provided to the network.
Upvotes: 1