oegedijk / explainerdashboard

Quickly build Explainable AI dashboards that show the inner workings of so-called "blackbox" machine learning models.
http://explainerdashboard.readthedocs.io
MIT License
2.32k stars 332 forks source link

[Bug] Version `0.4.6` seems to have introduced a bug - cannot access `explainer.X_merged` when `cats` not defined #298

Closed maxschulz-COL closed 8 months ago

maxschulz-COL commented 8 months ago

Hey - discovered the following after upgrading to 0.4.6:

from sklearn.ensemble import RandomForestClassifier
from explainerdashboard import ClassifierExplainer
from explainerdashboard.datasets import titanic_survive, titanic_names

X_train, y_train, X_test, y_test = titanic_survive()
train_names, test_names = titanic_names()
model = RandomForestClassifier(n_estimators=50, max_depth=5, random_state=1)
model.fit(X_train, y_train)

explainer = ClassifierExplainer(model, X_test, y_test,
                                # cats=['Deck', 'Embarked',
                                #     {'Gender': ['Sex_male', 'Sex_female', 'Sex_nan']}],
                                # cats_notencoded={'Embarked': 'Stowaway'}, # defaults to 'NOT_ENCODED'
                                # descriptions=feature_descriptions, # adds a table and hover labels to dashboard
                                labels=['Not survived', 'Survived'], # defaults to ['0', '1', etc]
                                idxs = test_names, # defaults to X.index
                                index_name = "Passenger", # defaults to X.index.name
                                target = "Survival", # defaults to y.name
                                )

The above code fails for 0.4.6, but not 0.4.5 - get

ValueError: No objects to concatenate

from

409             else:
    410                 cat_pieces.append(pd.DataFrame({col_name: X[col_name].values}))
--> 412 X_cats = pd.concat(cat_pieces, axis=1)
    414 if cols:
    415     X_cats = X_cats[cols]

Any help would be appreciated :) Thanks šŸ™ !

oegedijk commented 8 months ago

ah, thanks, apparently fixed one thing, broke another thing. Will investigate!

oegedijk commented 8 months ago

published 0.4.7 that should fix the issue: https://github.com/oegedijk/explainerdashboard/releases/tag/v0.4.7

maxschulz-COL commented 8 months ago

Awesome thanks šŸ™