Mapping column names to random forest feature importances

后端 未结 4 1254
-上瘾入骨i
-上瘾入骨i 2021-02-04 12:28

I am trying to plot feature importances for a random forest model and map each feature importance back to the original coefficient. I\'ve managed to create a plot that shows the

4条回答
  •  执念已碎
    2021-02-04 13:02

    Another simple way to get a sorted list

    importances = list(zip(xgb_classifier.feature_importances_, df.columns))
    importances.sort(reverse=True)
    

    Next code adds a visualization if it's necessary

    pd.DataFrame(importances, index=[x for (_,x) in importances]).plot(kind = 'bar')
    

提交回复
热议问题