Rf_feat_importance in fastai 1.0

Hello friends,

I cannot find rf_feat_importance equivalent in fastai 1.0

I tried grep -r etc…

Please help!

Tom

I’m new to this as well so anyone more experienced, feel free to correct me.

If you Google “rf_feat_importance”, the second or so search result should bring you to the original fastai source code: https://github.com/fastai/fastai/blob/master/old/fastai/structured.py

Lines #394-396:

def rf_feat_importance(m, df):
    return pd.DataFrame({'cols':df.columns, 'imp':m.feature_importances_}
                       ).sort_values('imp', ascending=False)

Either lift this entire one-line function into your own source code and execute it, or get the feature_importances_ attribute of your random forest model as shown above.

If you’re new to Python and Pandas, this function just constructs a new Pandas DataFrame with two columns, the 1st being the columns of the dataframe you used for your training set and the second being the feature_importances_ attribute associated with a RandomForestRegressor scikit-learn model.

Hope this helps.