Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
E

explainerdashboard

> DevOps
Open source

Quickly build Explainable AI dashboards that show the inner workings of so-called "blackbox" machine learning models.

2.5K stars0 likes1 views
WebsiteGitHub

About

Quickly build Explainable AI dashboards that show the inner workings of so-called "blackbox" machine learning models.

explainerdashboard

by: Oege Dijk

This package makes it convenient to quickly deploy a dashboard web app that explains the workings of a (scikit-learn compatible) machine learning model. The dashboard provides interactive plots on model performance, feature importances, feature contributions to individual predictions, "what if" analysis, partial dependence plots, SHAP (interaction) values, visualization of individual decision trees, etc.

You can also interactively explore components of the dashboard in a notebook/colab environment (or just launch a dashboard straight from there). Or design a dashboard with your own custom layout and explanations (thanks to the modular design of the library). And you can combine multiple dashboards into a single ExplainerHub.

Dashboards can be exported to static html directly from a running dashboard, or programmatically as an artifact as part of an automated CI/CD deployment process.

Examples deployed at: Fly.io, Hugging Face Space, detailed documentation at explainerdashboard.readthedocs.io, example notebook on how to launch dashboard for different models here, and an example notebook on how to interact with the explainer object here.

Works with scikit-learn, xgboost, catboost, lightgbm, and skorch (sklearn wrapper for tabular PyTorch models) and others.

Installation

You can install the package through pip:

pip install explainerdashboard

or conda-forge:

conda install -c conda-forge explainerdashboard

SageMaker Studio

SageMaker Studio runs notebooks and terminals in separate apps, so a common workflow is to export a dashboard config to disk and run it from the JupyterServer terminal. When running inside Studio, explainerdashboard can auto-detect SageMaker and apply the correct proxy prefixes, or you can set them explicitly.

Notebook example (export dashboard to disk):

python
db = ExplainerDashboard(
    explainer,
    mode="dash",
    port=8051,
    sagemaker=True,
)
db.to_yaml("dashboard.yaml", explainerfile="dashboard.joblib", dump_explainer=True)

Terminal example (run from the JupyterServer app):

bash
explainerdashboard run dashboard.yaml --sagemaker --port 8051 --no-browser

Access the dashboard via the Studio proxy URL:

<STUDIO_URL>/jupyter/default/proxy/8051/

If your Studio proxy path differs, you can override the prefixes:

bash
explainerdashboard run dashboard.yaml \
  --routes-pathname-prefix="/" \
  --requests-pathname-prefix="/jupyter/default/proxy/8051/"

Auto-detection uses the presence of /opt/ml/metadata/resource-metadata.json.

Demonstration:

(for live demonstration see Fly.io or Hugging Face Space)

Background

In a lot of organizations, especially governmental, but with the GDPR also increasingly in private sector, it is becoming more and more important to be able to explain the inner workings of your machine learning algorithms. Customers have to some extent a right to an explanation why they received a certain prediction, and more and more internal and external regulators require it. With recent innovations in explainable AI (e.g. SHAP values) the old black box trope is no longer valid, but it can still take quite a bit of data wrangling and plot manipulation to get the explanations out of a model. This library aims to make this easy.

The goal is manyfold:

  • Make it easy for data scientists to quickly inspect the workings and performance of their model in a few lines of code
  • Make it possible for non data scientist stakeholders such as managers, directors, internal and external watchdogs to interactively inspect the inner workings of the model without having to depend on a data scientist to generate every plot and table
  • Make it easy to build an application that explains individual predictions of your model for customers that ask for an explanation
  • Explain the inner workings of the model to the people working (human-in-the-loop) with it so that they gain understanding what the model does and doesn't do. This is important so that they can gain an intuition for when the model is likely missing information and may have to be overruled.

The library includes:

  • Shap values (i.e. what is the contributions of each feature to each individual prediction?)
  • Permutation importances (how much does the model metric deteriorate when you shuffle a feature?)
  • Partial dependence plots (how does the model prediction change when you vary a single feature?
  • Shap interaction values (decompose the shap value into a direct effect an interaction effects)
  • For Random Forest, XGBoost, and LightGBM models: visualisation of individual decision trees
  • Plus for classifiers: precision plots, confusion matrix, ROC AUC plot, PR AUC plot, etc
  • For regression models: goodness-of-fit plots, residual plots, etc.

The library is designed to be modular so that it should be easy to design your own interactive dashboards with plotly dash, with most of the work of calculating and formatting data, and rendering plots and tables handled by explainerdashboard, so that you can focus on the layout and project specific textual explanations. (i.e. design it so that it will be interpretable for business users in your organization, not just data scientists)

Alternatively, there is a built-in standard dashboard with pre-built tabs (that you can switch off individually)

Examples of use

Fitting a model, building the explainer object, building the dashboard, and then running it can be as simple as:

python
ExplainerDashboard(ClassifierExplainer(RandomForestClassifier().fit(X_train, y_train), X_test, y_test)).run()

Below a multi-line example, adding a few extra parameters. You can group onehot encoded categorical variables together using the cats parameter. You can either pass a dict specifying a list of onehot cols per categorical feature, or if you encode using e.g. pd.get_dummies(df.Name, prefix=['Name']) (resulting in column names 'Name_Adam', 'Name_Bob') you can simply pass the prefix 'Name':

…

If you are passing an sklearn/imblearn Pipeline, you can also clean up transformed feature names and let the explainer infer onehot groups automatically:

python
explainer = ClassifierExplainer(
    pipeline_model, X_test, y_test,
    strip_pipeline_prefix=True,      # e.g. "num__Age" -> "Age"
    feature_name_fn=None,            # optional custom rename function
    auto_detect_pipeline_cats=True,  # infer cats from transformed pipeline output
)

For a regression model you can also pass the units of the target variable (e.g. dollars):

python
X_train, y_train, X_test, y_test = titanic_fare()
model = RandomForestRegressor().fit(X_train, y_train)

explainer = RegressionExplainer(model, X_test, y_test,
                                cats=['Deck', 'Embarked', 'Sex'],
                                descriptions=feature_descriptions,
                                units = "$", # defaults to ""
                                )

ExplainerDashboard(explainer).run()

For pipeline-based models with post-processing/scaling, grouped categorical features passed through cats are now accepted as long as encoded columns are binary-like (not strictly only 0/1).

y_test is actually optional, although some parts of the dashboard like performance metrics will obviously not be available: ExplainerDashboard(ClassifierExplainer(model, X_test)).run().

You can export a dashboard to static html with db.save_html('dashboard.html').

You can pass a specific index for the static dashboard to display

ExplainerDashboard(explainer, index=0).save_html('dashboard.html')

or

ExplainerDashboard(explainer, index='Cumings, Mrs. John Bradley (Florence Briggs Thayer)').save_html('dashboard.html')

For a simplified single page dashboard try ExplainerDashboard(explainer, simple=True).

Show simplified dashboard screenshot

ExplainerHub

You can combine multiple dashboards and host them in a single place using ExplainerHub:

python
db1 = ExplainerDashboard(explainer1, title="Classifier Explainer",
         description="Model predicting survival on H.M.S. Titanic")
db2 = ExplainerDashboard(explainer2, title="Regression Explainer",
         description="Model predicting ticket price on H.M.S. Titanic")
hub = ExplainerHub([db1, db2])
hub.run()

You can adjust titles and descriptions, manage users and logins, store and load from config, manage the hub through a CLI and more. See the ExplainerHub documentation.

Show ExplainerHub screenshot

Dealing with slow calculations

Some of the calculations for the dashboard such as calculating SHAP (interaction) values and permutation importances can be slow for large datasets and complicated models. There are a few tricks to make this less painful:

  1. Switching off the interactions tab (shap_interaction=False) and disabling permutation importances (no_permutations=True). Especially SHAP interaction values can be very slow to calculate, and often are not needed for analysis. For permutation importances you can set the n_jobs parameter to speed up the calculation in parallel.
  2. Calculate approximate shap values. You can pass approximate=True as a shap parameter by passing shap_kwargs=dict(approximate=True) to the explainer initialization.
  3. Use GPU Tree SHAP by passing shap='gputree' when your model supports it. This requires an NVIDIA GPU and a CUDA-enabled SHAP build (see the SHAP docs).
  4. Storing the explainer. The calculated properties are only calculated once for each instance, however each time when you instantiate a new explainer instance they will have to be recalculated. You can store them with explainer.dump("explainer.joblib") and load with e.g. ClassifierExplainer.from_file("explainer.joblib"). All calculated properties are stored along with the explainer.
  5. Using a smaller (test) dataset, or using smaller decision trees. TreeShap computational complexity is O(TLD^2), where T is the number of trees, L is the maximum number of leaves in any tree and D the maximal depth of any tree. So reducing the number of leaves or average depth in the decision tree can really speed up SHAP calculations.
  6. Pre-computing shap values. Perhaps you already have calculated the shap values somewhere, or you can calculate them off on a giant cluster somewhere, or your model supports GPU generated shap values. You can simply add these pre-calculated shap values to the explainer with explainer.set_shap_values() and explainer.set_shap_interaction_values() methods.
  7. Plotting only a random sample of points. When you have a lots of observations, simply rendering the plots may get slow as well. You can pass the plot_sample parameter to render a (different each time) random sample of observations for the various scatter plots in the dashboard. E.g.: ExplainerDashboard(explainer, plot_sample=1000).run()

Launching from within a notebook

When working inside Jupyter or Google Colab you can use ExplainerDashboard(mode='inline'), ExplainerDashboard(mode='external') or `ExplainerDashboard(mode='jupyterlab

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Pythondashdashboarddata-scientistsexplainer

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
CategoryDevOps
PricingOpen source

> Related tools

D
Docker
容器化平台,标准化应用交付
G
GitHub Actions
GitHub 原生 CI/CD 工作流
N
Nginx
高性能 Web 服务器与反向代理