How are "feature_importances_" ordered in Scikit-learn's RandomForestRegressor

20,168

Solution 1

As mentioned in the comments, it looks like the order or feature importances is the order of the "x" input variable (which I've converted from Pandas to a Python native data structure). I use this code to generate a list of types that look like this: (feature_name, feature_importance).

zip(x.columns, clf.feature_importances_)

Solution 2

You may save the result in a pandas data frame as follows:

pandas.DataFrame({'col_name': clf.feature_importances_}, index=x.columns).sort_values(by='col_name', ascending=False)

By sorting it in a descending manner we get a hint to significant features.

Share:
20,168
Krishan Gupta
Author by

Krishan Gupta

Updated on July 27, 2021

Comments

  • Krishan Gupta
    Krishan Gupta almost 3 years

    If I run a model (called clf in this case), I get output that looks like this. How can I tie this to the feature inputs that were used to train the classifier?

    >>> clf.feature_importances_
    
    array([ 0.01621506,  0.18275428,  0.09963659,... ])