MATLAB: Feed Forward Neural Network – How to interpret the output

classificationfeed forwardneural network

I am trying to train a neural network and then use it to classify a sample set containing 4 classes (1, 2, 3 & 4).
I used my training data alongside some target group data as instructed in the newff doc.
However once the network was trained and I attempted to classify my sample using output = sim (net.sample) the result was not what I expected.
For each of my 2000 sample values the output was a column of four values ranging from -1.9 – 1.88 . I was expecting the neural network to assign a value of either 1, 2, 3, or 4 to each sample (as the SVM / nearest neighbour classification methods would). Have I gone drastically wrong somehwere or is this how the output it meant to be ?
Any advice would be greatly appreciated!

Best Answer

Use newff, newpr or patternnet with 'softmax', 'logsig' or 'purelin' as the output transfer function
For c classes use a target matrix that has columns of the c-dimensional unit matrix eye(c).
The relationships between the target matrix, integer (1:c) class index row vector, integer assigned class row vector, {0,1} error vector etc. are
target = ind2vec(classind); % columns of eye(c)
classind = vec2ind(target) % integers 1:c

net = train(net, input, target);
output = net(input);
assigned = vec2ind(output) % integers 1:c
errors = (assigned ~= classind )
Nerr = sum(errors)
Individual class performances are obtained using unique vector (NOT class) indices (1:N).
Hope this helps.
Thank you for formally accepting my answer
Greg
P.S. If you have further problem, try your code on one of the MATLAB classification datasets and we can compare.
help nndatasets