I created a GridSearchCV for a Random Forest Regressor. Now i want to check the feature importance. I searched around and I found this


This already works, but my trainingdata are huge, 669 Attributes therefore i need the attributenames so I found this code


But I dont know that the "named_steps["step_name"]" are.

I tried something like this

named_steps = X_train.columns

But this doesnt work. Could somebody explain me what "named_steps["step_name"]" is? Thank you and sorry for my noob questions


I think that you need just

feature_importances = rf_gridsearch.best_estimator_.feature_importances_

This provides the feature importances for all the attribures in your dataset. For more information on this as well as other options, you may also refer to Scikit-learn official documentation.

| improve this answer | |
  • $\begingroup$ I already tried that and i get this $\endgroup$ – ml_learner Jan 27 at 12:23
  • $\begingroup$ array([1.15007706e-02, 1.52749118e-02, 4.92813973e-03, 5.79714037e-03, .... for 669 Attributes. I want also the column name for the results $\endgroup$ – ml_learner Jan 27 at 12:24
  • 1
    $\begingroup$ The order of this values are the same as the order in the dataset. So the column names are just the X.columns $\endgroup$ – Giannis Krilis Jan 27 at 13:09
  • 1
    $\begingroup$ Yes, that's right! $\endgroup$ – Giannis Krilis Jan 28 at 9:40
  • 1
    $\begingroup$ @ml_learner I believe this answers your query. If so, please mark it as an Accepted Answer. That shall help others in future. :) $\endgroup$ – Random Nerd Jan 30 at 14:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.