Matlab Neural Net: Classifying Numerically Related Classes.

1 view (last 30 days)
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.

Accepted Answer

Greg Heath
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
haiderabc
haiderabc on 23 Jul 2013
Thanks for replying Greg. I appreciate your answering but appears as though you didn't understand my question or I didn't get your answer :)
From probabilies I mean that after I have trained my network, my targets should be in form of probabilies for given inputs. For example if I give height = 6 feet and weight = 70kg my output is the probabilities for XS, S, M, L and XL:
Input:
Height=6
Weight=70
Output:
XS=0.00685
S=0.03425
M=0.2055
L=0.411
XL=0.3425
I am already using vector based targets for example eye(5)...
Greg Heath
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

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!