1

I have a dataset with 5K (and 60 features) records focused on binary classification.

Please note that this solution doesn't work here

I am trying to generate feature importance using Permutation Feature Importance. However, I get the below error. Can you please look at my code and let me know whether I am making any mistake?

import eli5
from eli5.sklearn import PermutationImportance
logreg =LogisticRegression()
model = logreg.fit(X_train_std, y_train)
perm = PermutationImportance(model, random_state=1)
eli5.show_weights(perm, feature_names = X.columns.tolist())

I get an error like as shown below

AttributeError: 'PermutationImportance' object has no attribute 'feature_importances_'

Can you help me resolve this error?

The Great
  • 7,215
  • 7
  • 40
  • 128

1 Answers1

2

If you look at your attributes of PermutationImportance object via

ord(perm)

you can see all attributes and methods BUT after you fit your PI object, meaning that you need to do:

perm = PermutationImportance(model, random_state=1).fit(X_train,y)
Noah Weber
  • 312
  • 2
  • 13
  • Unfortunately, if I do `ord(perm)`, I get the below error `TypeError: ord() expected string of length 1, but PermutationImportance found`. Upvoted anyway for the response – The Great Dec 18 '19 at 23:25