Explainerdashboard
https://github.com/oegedijk/explainerdashboard
https://explainerdashboard.readthedocs.io/en/latest/
Installation
conda create -n test_env python=3.8
conda activate test_env
pip install explainerdashboard
Windows
> choco install graphviz
Quick start
from explainerdashboard.datasets import titanic_fare, titanic_names, feature_descriptions
from sklearn.ensemble import RandomForestRegressor
from explainerdashboard import RegressionExplainer
X_train, y_train, X_test, y_test = titanic_fare()
model = RandomForestRegressor(n_estimators=50, max_depth=5)
model.fit(X_train, y_train)
train_names, test_names = titanic_names()
explainer = RegressionExplainer(model, X_test, y_test,
cats=['Sex', 'Deck', 'Embarked'],
idxs=test_names,
target='Fare',
descriptions=feature_descriptions,
units="$")
Useage
model = RandomForestRegressor(n_jobs=-1, random_state=42)
model = model.fit(X_train, y_train)
explainer = RegressionExplainer(
model,
X_test,
y_test,
cats=["COL1", "COL2", "COL3"],
descriptions={"COL1": "aaa", "COL2", "bbb", "COL2", "ccc"},
target='Nice Name', # defaults to y.name
units='$',
# higher_is_better=False,
shap="tree",
)
Feature importance
explainer.mean_abs_shap_df(cats=True, cutoff=0.01)
explainer.permutation_importances_df(cats=False, topx=12)
Contributions
index = 0 # explain prediction for first row of X_test
explainer.contrib_df(index, cats=True, topx=8)
Hide components
https://github.com/oegedijk/explainerdashboard#hiding-components
Dashboard
ExplainerDashboard(
explainer,
title='TITLE',
orientation='horizontal',
hide_orientation=True,
# Tabs
importances=True,
model_summary=False,
contributions=True,
whatif=True,
shap_dependence=True,
shap_interaction=False
decision_trees=True
).run()
Plots
explainer.plot_importances(kind='shap', topx=5, cats=True)
explainer.plot_shap_summary(topx=10, cats=True)
explainer.plot_shap_contributions(index, cats=True, topx=8) # sort='high-to-low', orientation='horizontal'
explainer.plot_shap_contributions(name, cats=False)
explainer.plot_shap_dependence("Age") # color_col="Sex", highlight_index=5