Feature Importance with XGBClassifier

后端 未结 9 1164
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 10:03

Hopefully I\'m reading this wrong but in the XGBoost library documentation, there is note of extracting the feature importance attributes using feature_importances_

9条回答
  •  一生所求
    2020-12-14 10:44

    For xgboost, if you use xgb.fit(),then you can use the following method to get feature importance.

    import pandas as pd
    xgb_model=xgb.fit(x,y)
    xgb_fea_imp=pd.DataFrame(list(xgb_model.get_booster().get_fscore().items()),
    columns=['feature','importance']).sort_values('importance', ascending=False)
    print('',xgb_fea_imp)
    xgb_fea_imp.to_csv('xgb_fea_imp.csv')
    
    from xgboost import plot_importance
    plot_importance(xgb_model, )
    

提交回复
热议问题