Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get feature importance in xgboost by 'information gain'?

we can get feature importance by 'weight' :

model.feature_importances_

But this is not what i want. I want by importances by information gain.

we can get feature importance by 'gain' plot :

xgboost.plot_importance(model, importance_type='gain')

However, I don't know how to get feature importance data from above plot. Or

if there is function like model.feature_importances_ to give gain feature importance? Either of the two ways will work. Please let me know in comments if the question is not clear

like image 648
dsl1990 Avatar asked Feb 06 '23 15:02

dsl1990


1 Answers

You can get it from

model.booster().get_score(importance_type='gain')

http://xgboost.readthedocs.io/en/latest/python/python_api.html

like image 163
dsl1990 Avatar answered Feb 08 '23 13:02

dsl1990