Matlab Neural Net: Classifying Numerically Related Classes.
1 view (last 30 days)
Show older comments
Let’s say we have dataset of people's Heights and Weights as inputs and the T-Shirt size which they wear as outputs for example: XL, L, M, S, XS. I am using Matlab nprtool's default configuration for such problems, i.e. One-vs-All classification model with trainscg for traning & mse for performance evaluation.
The problem I am facing is that classification results are not very good. One obvious reason is that there is no way the neural net can explicitly judge that XL is closer to L than XS. In current setup, XL<->XS misclassification is considered same as XL<->L misclassification. Whereas XL<->L misclassification is not as problematic as XL<->XS.
I tried replacing XL, L, M, S and XS as numbers for example, XL=5, L=4, M=3, S=2 & XS=1 and used curve fitting tool which performed exceptionally well. But unfortunately I cannot use this model because I need output in terms of probabilities rather than concrete predictions. For example what I want is that I should be able to give height and weight and get probability for each of the classes (XL, L, M, S & XS).
I believe there should be a way to customize performance function. I would like to map my output classes on to numbers, multiply them with their probabilities and get a final output. For this output I will use mse for performance evaluation the way it is done in the context of curve fitting. My question is how do I do that in Matlab? Please note that I am fairly new to Matlab's nprtool so use layman type language rather than using nprtool's jargon.
0 Comments
Accepted Answer
Greg Heath
on 22 Jul 2013
Edited: Greg Heath
on 22 Jul 2013
There is no need to take the sequential nature of the output into account.
Just use 5-dimensional unit vectors with a single unit component to represent the class targets. The relationship between class indices (1:5) and target vectors eye(5)is
classindices = vec2ind(target)
and
target = ind2vec(classindices)
If you minimize mean-square-error or cross-entropy with purelin, logsig, or softmax output transfer functions, in spite of the fact the range [ 0 1] and normalization constraints sum(output) = ones(1,N) may not hold, the resulting outputs will be consistent estimates of the class posterior probabilities, conditional on the input.
If you use the logsig output transfer function, output./sum(output) will satisfy the constraints.
Probability relationships between classes will be displayed in the confusion matrices.
Hope this helps.
Thank you for formally accepting my answer
Greg
2 Comments
Greg Heath
on 23 Jul 2013
Edited: Greg Heath
on 23 Jul 2013
I understand your question and answered it. The bottom line is don't worry about the sequential nature of the outputs.
However, your problem may be due to something that you did not mention.
N = size(input,2)=size(target,2) = ?
How many examples in each class?
How many hidden nodes ?
How many random weight initialization trials ?
NMSE = mse(output-target)/mean(var(target',1)) ?
Nerr and PctErr for each class?
Posted code would help.
Greg
More Answers (0)
See Also
Categories
Find more on Define Shallow Neural Network Architectures in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!