Get feature importance from GridSearchCV

Nick M picture Nick M · Jan 22, 2018 · Viewed 17.6k times · Source

Is there a way to get feature importance from a sklearn's GridSearchCV?

For example :

from sklearn.model_selection import GridSearchCV
print("starting grid search ......")
optimized_GBM = GridSearchCV(LGBMRegressor(),
                             params,
                             cv=3,
                             n_jobs=-1)
# 
optimized_GBM.fit(tr, yvar)
preds2 = optimized_GBM.predict(te)

Is there a way I can access feature importance ?

Maybe something like

optimized_GBM.feature_importances_

Answer

Aptha Gowda picture Aptha Gowda · Apr 13, 2018

This one works

optimized_GBM.best_estimator_.feature_importances_