machine-learningscikit-learnxgboost

XGBoost get feature importance as a list of columns instead of plot


I am wondering if you we can get the feature importance as a list of columns instead of a plot. This is what I have

xg_reg = xgb.train(params=params, dtrain=data_dmatrix, num_boost_round=10)
import matplotlib.pyplot as plt

xgb.plot_importance(xg_reg)
plt.rcParams['figure.figsize'] = [5,5]
plt.show()

Which gives me this plot

enter image description here

I would like to instead just get a list of the top features since I have over 800 different features.


Solution

  • You can use xgb.get_score(). Here are a number of examples: How to get feature importance in xgboost?