How to get feature importance in xgboost?

后端 未结 11 1783
情深已故
情深已故 2020-12-13 07:00

I\'m using xgboost to build a model, and try to find the importance of each feature using get_fscore(), but it returns {}

and my train code

11条回答
  •  被撕碎了的回忆
    2020-12-13 07:34

    Get the table containing scores and feature names, and then plot it.

    feature_important = model.get_booster().get_score(importance_type='weight')
    keys = list(feature_important.keys())
    values = list(feature_important.values())
    
    data = pd.DataFrame(data=values, index=keys, columns=["score"]).sort_values(by = "score", ascending=False)
    data.plot(kind='barh')
    

    For example:

提交回复
热议问题