NLTK package provides a method show_most_informative_features()
to find the most important features for both class, with output like:
contains(outstanding) = True pos : neg = 11.1 : 1.0
contains(seagal) = True neg : pos = 7.7 : 1.0
contains(wonderfully) = True pos : neg = 6.8 : 1.0
contains(damon) = True pos : neg = 5.9 : 1.0
contains(wasted) = True neg : pos = 5.8 : 1.0
As answered in this question How to get most informative features for scikit-learn classifiers? , this can also work in scikit-learn. However, for binary classifier, the answer in that question only outputs the best feature itself.
So my question is, how can I identify the feature's associated class, like the example above (outstanding is most informative in pos class, and seagal is most informative in negative class)?
EDIT: actually what I want is a list of most informative words for each class. How can I do that? Thanks!
Best Answer
In the case of binary classification, it seems like the coefficient array has been flatten.
Let's try to relabel our data with only two labels:
[out]:
So let's do some diagnostics:
[out]:
Seems like the features are counted and then when vectorized it was flattened to save memory, so let's try:
[out]:
Now we see some patterns... Seems like the higher coefficient favors a class and the other tail favors the other, so you can simply do this:
[out]:
Actually if you've read @larsmans comment carefully, he gave the hint on the binary classes' coefficient in How to get most informative features for scikit-learn classifiers?