2
$\begingroup$

Is there a way in scikit-learn to compute (or to obtain) the features importance of each class to predict? I known feature_importances_ properties of tree models, but I'm interested in a separate list of more importante predictors for the first class, a separate list for the second class and so on.

E.G: which are the most important features for the Male class? And which are the most important features for the Female class?

$\endgroup$

1 Answer 1

4
$\begingroup$

The implementation in scikit-learn is based in the formal definition of feature importances given by Friedman [1] in 2001. Since the concept of "feature importance" its somehow fuzzy, Friedman linked his definition to one specific classification method, gradient boosting trees, which by default can handle multi-class classification problems. As far as I know, there is not a formal definition of class-specific importance for any classification method.

That said, I believe you could apply a simple trick to obtain what could be regarded as class-specific feature importances. For instance, imagine you have a classification problem with classes $A$,$B$ and $C$. Instead of training a single gradient boosting trees model for all classes, you could use a one-vs-all [2] strategy and train one model with the samples from $A$ as positive and the samples from $B$,$C$ as negative. Then you train a model with the samples from $B$ as positive and the samples from $A$,$C$ as negative. And finally a classifier with the samples from $C$ as positive and the samples form $A$,$B$ as negative.

After training your models, you could interpret the feature importances reported by the first model as the importances to separate $A$ form the other classes, the importances reported by the second model as the importances to separate $B$ from the rest, and so on.

If your problem has only two classes, then the above approach will yield the same importances vector for both classes, so I won't be very useful. In that case perhaps you might find it useful to compute some representative or prototypical samples from each class (for instance, by using k-Means).

Hope that was of help.

[1] Friedman, J. H. (2001). Greedy function approximation: a gradient boosting machine. Annals of statistics, 1189-1232.

[2] https://en.wikipedia.org/wiki/Multiclass_classification#One-vs.-rest

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.