Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pandas.core.indexes.base.Index not supported for feature_names params in show_weights #408

Open
TremaMiguel opened this issue Jun 12, 2021 · 0 comments

Comments

@TremaMiguel
Copy link

If argument feature_names in function eli5.show_weights() is pandas.core.indexes.base.Index raises an TypeError: Unexpected feature_names type.

To reproduce

import eli5

from eli5.sklearn import PermutationImportance
from sklearn.ensemble import RandomForestRegressor
from sklearn.model_selection import train_test_split
from sklearn.datasets import load_boston

data = load_boston()
X, y, feats  = data['data'], data['target'], data['feature_names']
X = pd.DataFrame(X, columns=feats)

# Split in train-test
X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=0)

# Fit model
reg = RandomForestRegressor()
reg.fit(X_train, y_train)

# Run permutation importance
perm = PermutationImportance(reg, random_state=1).fit(X_test, y_test)

# Show weights with pandas.Index
eli5.show_weights(perm, top=None, feature_names=X_test.columns)
>>> TypeError: Unexpected feature_names type

Discussion

Reading the functionality of the FeatureNames class, noticed that some functionalities that feature_names param should satisfy are

cols = X_test.columns

# size
len(cols) 

# indexing
t[5]

# iterable
enumerate(cols)

so my question if it is possible to add support for pandas.core.indexes.base.Index as argument in show_weights function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant