For the complete documentation index, see llms.txt. This page is also available as Markdown.

Interpretable & Explainable AI (XAI)

A calibrated score still does not say why the model produced it, and that is the question explainability answers. The page opens with the field as a whole, its courses, surveys, the argument for interpretable models, and the libraries, then narrows to the three explainers most people reach for: LIME, Anchor, and SHAP.

The same notes are in Books & notebooks.

XAI

Before choosing a tool it helps to see the map of the field, starting with the overview figure below.

Explainable AI.

The gentlest entry is DeepFindr's "Explainable AI explained!" A series of videos about XAI. For breadth, the "Explainable AI resources" spreadsheet is A curated document about XAI research resources.

The full academic route is the Interpretability and Explainability in Machine Learning course / slides. Understanding, evaluating, rule based, prototype based, risk scores, generalized additive models, explaining black box, visualizing, feature importance, actionable explanations, casual models, human in the loop, connection with debugging. The same teacher's material continues in three places: the Hima_CHIL.pptx deck Explainable Machine Learning: Understanding the Limits & Pushing the Boundaries; a tutorial by Hima Lakkaraju, the ACM "Tutorial: Explainable ML in the Wild" (tutorial VIDEO on youtube); and her twitter thread announcing a full seminar course on explainability in ML at Harvard, with last year's version of the course linked, under the line "If you think that's all we have got, you are wrong!". The figure below comes from that tutorial material.

Explainable AI tutorial figure.

The field has a dissenting voice that is worth hearing early: Stop Explaining Black Box Machine Learning Models for High Stakes Decisions and Use Interpretable Models Instead. A great talk on the topic by Shir Meir Lador goes with it.

The tutorials then show both how to explain and when to doubt the explanation. The explainML tutorial is the NeurIPS 2020 tutorial page, the “Webpage for AAAI 2021, NeuRIPS 2020, and CPAIOR 2021 tutorials.” Its counterweight is the FAccT 2021 deck by Shalmali Joshi, Chirag Agarwal, and Hima Lakkaraju, When not to trust explanations :).

From the above image: Paper: Principles and practice of explainable models - a really good review for everything XAI - “a survey to help industry practitioners (but also data scientists more broadly) understand the field of explainable machine learning better and apply the right tools. Our latter sections build a narrative around a putative data scientist, and discuss how she might go about explaining her models by asking the right questions. From an organization viewpoint, after motivating the area broadly, we discuss the main developments, including the principles that allow us to study transparent models vs opaque models, as well as model-specific or model-agnostic post-hoc explainability approaches. We also briefly reflect on deep learning models, and conclude with a discussion about future research directions.”

A survey is easier to use next to a book. Book: interpretable machine learning opens its methods overview with a taxonomy, a map so the reader can see the forest for the trees before diving into individual models and methods; its author's site is christoph mulner, which has since moved to christophmolnar.com. (great) Interpretability overview, transparent (simultability, decomposability, algorithmic transparency) post-hoc interpretability (text explanation, visual local, explanation by example,), evaluation, utility. Medium: the great debate is Kirthi Shankar Sivamani on why interpretability comes into question as deep learning models, now state of the art in image processing, NLP, and recommendation, get deployed.

The great AI debate on interpretability.

Knowing the methods is not enough; they can be misread. Paper: pitfalls to avoid when interpreting ML models “A growing number of techniques provide model interpretations, but can lead to wrong conclusions if applied incorrectly. We illustrate pitfalls of ML model interpretation such as bad model generalization, dependent features, feature interactions or unjustified causal interpretations. Our paper addresses ML practitioners by raising awareness of pitfalls and pointing out solutions for correct model interpretation, as well as ML researchers by discussing open issues for further research.” - mulner et al.

Pitfalls when interpreting ML models.

With the pitfalls in mind, the practical write-ups come next. Rated three stars (***), whitening a black box. This is very good, includes eli5, lime, shap, many others. The code behind it is The notebook! in the KagglePlaygrounds repo, and the post itself is the Blog. For a whole book on the subject, exploratory model analysis introduces a unified language for exploration, explanation and examination of predictive machine learning models.

The libraries turn that language into code. Alibi-explain - White-box and black-box ML model explanation library. Alibi is an open source Python library aimed at machine learning model inspection and interpretation. The focus of the library is to provide high-quality implementations of black-box, white-box, local and global explanation methods for classification and regression models.

Alibi explain library.

For a guided course, Hands on explainable ai is the youtube talk, and its code is the Packt git repo for Explainable AI with Python. A warning belongs next to all these tools: Explainable methods are not always consistent and do not agree with each other, this article has a make-sense explanation and flow for using shap and its many plots.

For CNNs, the figure below shows the vision-specific options.

Keras-vis for cnns, 3 methods, activation maximization, saliency and class activation maps

Beyond this page, the same spreadsheet has More resources!

Gradient-based methods hide a choice that changes the answer. Visualizing the impact of feature attribution baseline - Path attribution methods are a gradient-based way of explaining deep models. These methods require choosing a hyperparameter known as the baseline input. What does this hyperparameter mean, and how important is it? In this article, we investigate these questions using image classification networks as a case study. We discuss several different ways to choose a baseline input and the assumptions that are implicit in each baseline. Although we focus here on path attribution methods, our discussion of baselines is closely connected with the concept of missingness in the feature space - a concept that is critical to interpretability research.

Google's interactive tools let you probe a model instead of reading a plot. The WHAT IF TOOL - GOOGLE notebook runs the smile detector in Colab, and the walkthrough uses UCI Census data. Language interpretability tool (LIT) - The Language Interpretability Tool (LIT) is an open-source platform for visualization and understanding of NLP models.

The interpretable-first argument comes back in its abstract form. Stop Explaining Black Box Machine Learning Models for High Stakes Decisions and Use Interpretable Models Instead - “trying to \textit{explain} black box models, rather than creating models that are \textit{interpretable} in the first place, is likely to perpetuate bad practices and can potentially cause catastrophic harm to society. There is a way forward -- it is to design models that are inherently interpretable. This manuscript clarifies the chasm between explaining black boxes and using inherently interpretable models, outlines several key reasons why explainable black boxes should be avoided in high-stakes decisions, identifies challenges to interpretable machine learning, and provides several example applications where interpretable models could potentially replace black box models in criminal justice, healthcare, and computer vision.”

Other angles on the same problem follow. Using genetic algorithms is Federico Piccinini on interpreting black-box models whose predictions are becoming increasingly difficult, and sometimes impossible, to understand. Google’s what-if tool is the smile detector demo, from PAIR, the People + AI Research team at Google that explores the human side of AI. Boruta (medium) was designed to automatically perform feature selection on a dataset using randomized features, i.e., measuring valid features against their shadow/noisy counterparts; the post explains why selecting only the relevant features removes unnecessary noise.

The same notes are in FEATURE SELECTION.

Microsoft's toolkit covers both halves of the field. InterpretML is an open source toolkit for analyzing models and explaining behavior, and its git repo, by Microsoft, lets you fit interpretable models and explain blackbox machine learning. Interpretability also connects to robustness: Connecting Interpretability and Robustness in Decision Trees through Separation is the ICML poster, with code in its git repo. For language models, Interpret Transformers - explain transformers with 2 lines of code.

Lime

Among all those tools, LIME is the first local explainer most people learn: it explains one prediction at a time. The same notes are in FEATURE IMPORTANCE.

*** how lime works behind the scenes is Chris Kuo starting from the questions the inventors of LIME were concerned with and then walking through their solutions. LIME to interpret models introduces the technique to explain the predictions of any machine learning classifier, for NLP and IMAGE, with the github- repo. In the experiments in our research paper, "Why Should I Trust You?", we demonstrate that both machine learning experts and lay users greatly benefit from explanations similar to Figures 5 and 6 and are able to choose which models generalize better, improve models by changing them, and get crucial insights into the models' behavior.

Anchor

A LIME explanation holds near one point, but it does not say how far. Anchor, from the same authors, answers that with a rule.

Anchor from the authors of Lime, - An anchor explanation is a rule that sufficiently “anchors” the prediction locally – such that changes to the rest of the feature values of the instance do not matter. In other words, for instances on which the anchor holds, the prediction is (almost) always the same.

Shap

Local rules still leave open how to divide a prediction fairly among features, and SHAP answers that with game theory. The same notes are in FEATURE IMPORTANCE.

The theory comes first. Data Science Garage's "How SHAP value is calculated? It is not hard! (simple example)" shows how Shap values are calculated on youtube. Cooporative game theory & Shapely values is Anshika Parihar's Medium post. Vincent Knight's "Cooperative Games and the Shapley value" is on youtube, and his worked example is Calculating a Taxi fare using Shap. Shap explained presents SHAP, SHapley Additive exPlanations, first published in 2017 by Lundberg and Lee, as a way to reverse-engineer the output of any predictive algorithm.

The two libraries are easiest to compare side by side. Intro to shap and lime part 1 is a brief technical introduction with code and output showing pros and cons of each, and part 2 shows how to use them in practice and interpret their output.

A series on Shap, Lime, by Chris Kuo, walks the same ground in order:

Two older pointers, Medium Intro to lime and shap and the four-star In depth SHAP post, are kept at the end of the page. The library itself is on Github: a game theoretic approach to explain the output of any machine learning model.

Worked examples show SHAP on real data. Sara Robinson's "Preventing bias in ML models, with code" explains Country happiness using shap. The Stackoverflow example, predicting tags, pandas keras etc leverages Stack Overflow data and Google's Cloud AI. An intro to shapely and shap is also kept at the end of the page. Fiddler on shap is Fiddler Labs applying SHAP to predicting loan defaults on Lending Club data.

Shapash wraps SHAP and LIME in a user-friendly interface for reliable and transparent models. The shapash git - repo is MAIF's; it serves as a web app and works on both explainers (lime and shap) . making models understandable by everyone is by Yann Golhen. using shapash for confidence on XAI. is by francesco marini, on explaining black-box decision-making, using 3 new metrics:

  • Consistency - do different explainability methods give, on average, similar explanations?

  • Stability - for similar instances, are the explanations similar?

  • Compacity - do fewer features drive the model?

SHAP can also point at the features that fail on new data, which is Partial Shap: Which Of Your Features Are Overfitting? by Samuele Mazzanti - "Discover “ParShap”: an advanced method to detect which columns make your model underperform on new data" implemented in pingouin-stats. (Medium link) And Shapley values have limits of their own, measured by Shap residuals in this medium post.

For SHAP advanced, follow these in order:

  1. What are shap values on kaggle - whatever you do start with this: https://www.kaggle.com/dansbecker/shap-values

  2. Shap values on kaggle #2 - continue with this: https://www.kaggle.com/dansbecker/advanced-uses-of-shap-values

  3. How to calculate Shap values per class based on this graph

SHAP values per class.

SHAP is one way among many. "How To Explain The Prediction Of A Machine Learning Model" is A thorough post about the many ways of explaining a model, from regression, to bayes, to trees, forests, lime, beta, feature selection/elimination. Trusting models is the "Why Should I Trust You?" paper behind LIME. Interpret using uncertainty is Yoel Zeldes on how growing DNN complexity makes interpretability a new challenge, and uncertainty a way into it. Shap in Python presents SHAP as the Python package for understanding and debugging models, showing how each feature contributed to an individual prediction and, aggregated, the trends across predictions.

Several of the posts above also live at their original towardsdatascience addresses. Explainable methods is "Interpretable Machine Learning using SHAP - theory and applications", by Khalil Zlaoui: https://towardsdatascience.com/interpretable-machine-learning-with-xgboost-9ec80d148d27. Using genetic algorithms is an adversarial explanation approach to interpreting complex machine learning predictions, by Federico Piccinini: https://towardsdatascience.com/interpreting-black-box-machine-learning-models-with-genetic-algorithms-a803bfd134cb. The Boruta (medium) post, "If you aren't using Boruta for feature selection, you should", by Aaron Lee: https://towardsdatascience.com/boruta-explained-the-way-i-wish-someone-explained-it-to-me-4489d70e154a. Shap explained, a tool that shows how each feature affects every prediction of the model, by Vinicius Trevisan: https://towardsdatascience.com/shap-explained-the-way-i-wish-someone-explained-it-to-me-ab81cc69ef30. Part I: Explain Your Model with the SHAP Values: https://towardsdatascience.com/explain-your-model-with-the-shap-values-bc36aac4de3d. Using shapash for confidence on XAI, open-sourced metrics to evaluate the quality of explanations: https://towardsdatascience.com/building-confidence-on-explainability-methods-66b9ee575514. The Shap residuals medium post, which uses bar trivia to show information missed by Shapley values, by Max Cembalest: https://towardsdatascience.com/shapley-residuals-measuring-the-limitations-of-shapley-values-for-explainability-d9cdc3582522. Shap in Python, by Vinicius Trevisan: https://towardsdatascience.com/introduction-to-shap-with-python-d27edc23c454. The ParShap tool from "Which Of Your Features Are Overfitting?" is pingouin-stats (Medium link): https://pingouin-stats.org/. Finally, the Alibi documentation survives as an archived copy: https://web.archive.org/web/2020/https://docs.seldon.io/projects/alibi.

  • Alibi. This address no longer opens: https://docs.seldon.io/projects/alibi

  • Official shap tutorial on their plots, you can never read this too many times.. This address no longer opens: https://slundberg.github.io/shap/notebooks/plots/decision_plot.html

  • Intro to shapely and shap. This address no longer opens: https://towardsdatascience.com/a-new-perspective-on-shapley-values-an-intro-to-shapley-and-shap-6f1c70161e8d?

  • Part V: Explain Any Models with the SHAP Values — Use the KernelExplainer. This address no longer opens: https://towardsdatascience.com/explain-any-models-with-the-shap-values-use-the-kernelexplainer-79de9464897a

  • Medium Intro to lime and shap. This address no longer opens: https://towardsdatascience.com/explain-nlp-models-with-lime-shap-5c5a9f84d59b

    • In depth SHAP. This address no longer opens: https://towardsdatascience.com/introducing-shap-decision-plots-52ed3b4a1cba

  • Which Of Your Features Are Overfitting? by Samuele Mazzanti - "Discover “ParShap”: an advanced method to detect which columns make your model underperform on new data" implemented in pingouin-stats. (Medium link). This address no longer opens: https://towardsdatascience.com/which-of-your-features-are-overfitting-c46d0762e769

  • a tutorial by Hima Lakkaraju (tutorial VIDEO. This address no longer opens: https://www.chilconference.org/tutorial_T04.html

Last updated

Was this helpful?