IndicoDataSolutions / Passage

A little library for text analysis with RNNs.
MIT License
530 stars 134 forks source link

Understanding Multiclass classification problem #36

Open naeemulhassan opened 9 years ago

naeemulhassan commented 9 years ago

Here is the thing.

I have 3 class labels in my data. The predict function returns an array of shape (N, 3) where N is the size of the train set. Here is an example,

>>> prediction = model.predict(tokenizer.transform(test_text))
>>> prediction
    array([[ 0.99999995,  0.99998585,  0.99999268],
       [ 0.99999993,  0.99998351,  0.99999069],
       [ 0.9999999 ,  0.99997884,  0.99998756],
       [ 0.99999992,  0.99998125,  0.99998932],
       [ 0.99999988,  0.99997679,  0.99998638],
       [ 0.99999996,  0.99998655,  0.99999323],
       [ 0.99999942,  0.99992762,  0.99995597],
       [ 0.99999987,  0.99997481,  0.99998479],
       [ 0.99999995,  0.99998605,  0.99999269],
       [ 0.99999996,  0.99998733,  0.99999372]])

How to interpret the prediction. I have 3 class labels but the array is giving close to 1 in all the classes. The value don't even sum up to 1. I must be doing something wrong. Any suggestion is highly appreciated.

Thanks!

youralien commented 9 years ago

@naeemulhassan Mind posting your code so I can try to reproduce this error?

I turned the gender two class problem into a multiclass problem, by replacing sigmoid with softmax, setting the size of the final dense layer equal to 2, and bce (binary cross entropy) with cce (categorical cross entropy).

It's important that the multi-class problem is handled through a softmax, because the softmax outputs a normalized distribution of probability values for the classes. I hope this was the simple change you needed! Let me know and we can try to hash it out together.

Check out the gender_multiclass.py file in my PR: https://github.com/IndicoDataSolutions/Passage/pull/39