Solved – Class-specific feature importance

machine learningpythonrandom forest

I have rather a simple question which I have not had any luck finding the answer to. I'm training a Random Forest classifier using sklearn in Python 2.7, on a large dataset ~(80k,250) where observations are movie reviews and features are attributes of critic and movie. Targets are "positive review" (1) or "negative review" (0).

My reason for training this classifier is so I can investigate feature importances. Just extracting the feature importances is a simple task, using feature_importances_. This produces an array of GINI estimates for each feature. What this, however, does not tell me is which classification ("pos"/"neg") that a specific feature is typical to. In other words, does having Clint Eastwood in your movie affect the scores given by critics positively or negatively?

Is there a simple way to get these class-specific feature importances? Is there a complicated way? Is there a way at all?

Best Answer

The simplest method I could think of is finding the ratio between the "positive" and "negative" rows where your feature is present. I.e. for all movies where Clint Eastwood is playing, what is the ratio between positive reviews and negative reviews? Are there many more positive than negative reviews?

I suppose there are different formulas you could use - pos/neg, pos/(pos+neg), pos-neg, etc.