Skip to main content

Visual Explanations of the Explainers, to Gain Insight into Predictions from High-Dimensional Models

Authors
Affiliations

Janith Wanniarachchi

Monash University

Dianne Cook

Monash University

Kate Saunders

Monash University

Patricia Menendez

University of Melbourne

Thiyanga Talagala

University of Sri Jayewardenepura

Abstract

Explainable Artificial Intelligence (XAI) methods such as SHAP, Counterfactuals and Anchors are used on black box models to understand the contributions from features. Traditional analysis of XAI methods focuses primarily on using numerical values to assess feature contributions. Visualising these explanations together with the observed data gives a clear picture of which facets of the model are explained by each method. In this paper, we propose a set of geometric representations for visualising XAI methods in a two dimensional data space. The representations build intuition for how each method works, showing that the contribution indicated by SHAP is a different quantity from that indicated by LIME, and help explain why different methods can return different explanations for the same prediction. We hope these representations will also aid in researchers who are applying XAI methods to their research problem without being affected by confirmation bias in picking methods that affirm their prior beliefs.

1 Introduction

Machine learning methods have become popular in tasks such as genome sequencing, climate modeling and natural language tasks. This shift is largely driven by the non-parametric nature of machine learning algorithms, which allows them to map connections between input variables with minimal human intervention or prior assumptions. However, since the analytical connections are learned implicitly rather than predetermined by the user, the underlying model behavior becomes highly opaque. As these models are increasingly deployed in public facing scenarios, understanding their inner workings is of paramount importance.

Explainable Artificial Intelligence (XAI) methods emerged in response to the increasing complexity and opaqueness of machine learning models and the need to understand how they work, particularly deep learning models. A central aim of XAI is to provide algorithmic and mathematical methods that gather insights into how black box models make decisions, addressing concerns related to trust, transparency, and accountability in AI systems (Ali et al. 2023).

Interpreting how predictors relate to a response is not new to statistics. In parametric models such as linear and generalized linear models, the fitted coefficients describe the effect of each predictor directly, and the statistical tradition has long emphasized interpretation alongside prediction (Breiman 2001b). As models become more flexible, coefficients lose this direct meaning, and statisticians have turned to quantities computed from the model’s predictions instead. Marginal effects, predictions and comparisons summarize how the predicted response changes as one predictor changes, and can be computed for any model, as implemented in the marginaleffects package (Arel-Bundock et al. 2024). Partial dependence plots (Friedman 2001) and accumulated local effects (Apley and Zhu 2020) apply the same idea to black box models by averaging predictions over the data (Molnar 2022). Variable importance measures, such as the permutation importance introduced for random forests (Breiman 2001a) and its extension to whole classes of models (Fisher et al. 2019), rank predictors by how much the model relies on them. These statistical tools and XAI methods share a common aim, describing a fitted model through its predictions, and differ mainly in whether they summarize the model over the whole dataset or at a single observation.

XAI methods are commonly distinguished by their scope and by the range of models they apply to (Molnar 2022). By scope, a method is either global or local (Molnar et al. 2020). Local methods describe the model’s decision process, or the influence of each feature, for a single observation of interest. Global methods describe the effect of the predictors across the entire dataset, often by aggregating local explanations. Partial dependence plots (Friedman 2001; Greenwell et al. 2017) and accumulated local effect plots (Apley and Zhu 2020) are common global methods, while SHAP (Lundberg and Lee 2017), Anchors (Ribeiro et al. 2018) and counterfactuals (Wachter et al. 2018) are common local methods.

By the range of models they apply to, methods are either model-specific, able to explain only one family of models such as tree-based models or neural networks, or model-agnostic, able to explain any black box model regardless of its architecture. Model specific methods use underlying information about the model’s architecture to provide explanations while the model agnostic methods use the model as a function of the input data to approximate the internal workings of the model. Most XAI methods are model agnostic with a few model specific methods available specifically to deep learning models such as saliency maps (Simonyan et al. 2013) and learned feature visualization (Olah et al. 2017) where information on the internal gradients are available.

Model agnostic methods are robust to a wider range of models and therefore can be used in a multitude of contexts, while local interpretability methods provide a narrower inspection into the decision process of black box models.

Despite the advances in the current landscape of XAI methods, the explanations from these methods are inspected in isolation from the components that lead up to the explanation. Currently many of the XAI visualisation methods such as ModelStudio (Baniecki and Biecek 2019) focus primarily on showing feature contributions of the model based on different explanation methods (Baniecki et al. 2023). While these visualisations are effective in communcating the numerical values from explanations, these visualisations also suffer from being unable to communicate how the underlying explanations relate to the model’s view of the data and the data itself.

This isolation brings forward the issue of practitioners having to navigate a fragmented ecosystem of XAI techniques without a unified framework to guide them (Lundberg and Lee 2017). As different XAI methods probe different mathematical facets of a model, they inherently capture different aspects of the decision-making process. Consequently, when multiple methods are applied to the same pipeline, they frequently yield conflicting explanations. Resolving these disagreements currently forces practitioners to manually reconcile abstract algorithmic formulas with raw numerical outputs.

This paper uses visualisation to build intuition for how each explainer works, and for why different explainers can return different explanations for the same prediction. Each explanation is drawn as a geometric object in the data space, alongside the data, the model’s predictions and the perturbations the explainer used to produce it. Seeing these layers together shows what question each method answers, and makes it possible to trace a disagreement back to the step in the explanation process where the methods part ways.

The remainder of this paper is organized as follows. Section 2 establishes a foundational baseline by outlining a generalized predictive modeling workflow, followed by the proposed visualization approaches for this pipeline in Section 2.3. To ground the geometric framework, Section 2.1 introduces the simulated dataset and Section 2.2 the model used throughout the paper. Subsequently, Section 4 establishes the formal mathematical definitions of the XAI methods under review, setting the stage for the conceptual design and implementation of geometric XAI visualizations. Finally, Section 5 discusses the potential solutions to settle the disagreement between XAI explanations.

2 Understanding the building blocks behind the prediction workflow

The general workflow for prediction is shown in Figure 1. It begins with a dataset of \(N\) observations \(\mathcal{D} = \{(\mathbf{x}_1, y_1), \dots, (\mathbf{x}_N, y_N)\}\), where each \(\mathbf{x}_i = (x_{i1}, \dots, x_{ip})\) is a vector of \(p\) feature values and \(y_i\) is the corresponding response. In this general setting the response may be categorical, giving a classification problem, or continuous, giving a regression problem, and the features may be numeric or categorical. The dataset is partitioned into a training dataset \(\mathcal{D}_{\text{train}}\) and a testing dataset \(\mathcal{D}_{\text{test}}\), with \(\mathcal{D}_{\text{train}} \cap \mathcal{D}_{\text{test}} = \emptyset\). A learning algorithm is applied to \(\mathcal{D}_{\text{train}}\) to produce a fitted model \(\hat{f}\), which maps a feature vector \(\mathbf{x}\) to a prediction \(\hat{y} = \hat{f}(\mathbf{x})\). The testing dataset is held out during training. The fitted model is applied to it to obtain predictions \(\hat{y}_k = \hat{f}(\mathbf{x}_k)\) for each \((\mathbf{x}_k, y_k) \in \mathcal{D}_{\text{test}}\), and comparing \(\hat{y}_k\) with the observed \(y_k\) measures how well the model generalizes to unseen data.

The XAI methods considered in this paper apply to both classification and regression. The geometric representations developed in later sections, however, are currently defined for classification, and this paper focuses on binary classification with numeric features.

flowchart LR
    A["Dataset 𝒟"] --> B["Training set 𝒟<sub>train</sub>"]
    A --> C["Testing set 𝒟<sub>test</sub>"]
    B --> D["Fitted model f̂"]
    C --> F["Predictions ŷ = f̂(x)"]
    D --> F
    F --> G["Evaluate: ŷ vs y"]
Figure 1: The workflow when the goal is to optimize for prediction. The dataset \(\mathcal{D}\) is split into disjoint training and testing sets; the model \(\hat{f}\) is fitted on the training set only and scored by comparing its predictions \(\hat{y}\) with the observed responses \(y\) in the testing set. Explanations, introduced in Section 3, are added on top of this pipeline rather than replacing it.

2.1 The dataset

To illustrate the problem, this paper uses a simulated two-dimensional binary classification dataset, \(\mathcal{D}\), where \(p = 2\) and \(y_i \in \{A, B\}\) for \(i = 1, \dots, N\), with \(A\) and \(B\) denoting the two class labels. The dataset contains \(N =\) 5000 observations of two numeric features, where each feature is drawn independently from a uniform distribution, \(x_{ij} \sim U(-1, 1)\) for \(j = 1, 2\). The class of each observation is assigned by the following rule, where the cases are checked from top to bottom and the first that applies sets the class.

\[ y_i = \begin{cases} B, & \text{if } x_{i2} < -1 + 0.8x_{i1} \\[6pt] A, & \text{if } x_{i1} < -0.5 \text{ AND } x_{i2} < -0.3 \\[6pt] A, & \text{if } -0.5 \le x_{i1} < 0.4 \text{ AND } x_{i2} < 0.1 + 0.8x_{i1} \\[6pt] A, & \text{if } x_{i1} \ge 0.4 \\[6pt] B, & \text{otherwise} \end{cases} \]

The dataset is split at random into a training set of 4000 observations and a testing set of 1000 observations.

Four observations of interest, shown in Figure 2, were chosen in the feature space to demonstrate how XAI methods explain individual predictions. Each lies within about 0.01 of the model’s prediction boundary, next to a different part of it, where local explanations are most difficult and where explainers are most likely to disagree. Point 1, at \((0, 0.1)\), lies on the upper sloped edge \(x_2 = 0.1 + 0.8x_1\). Point 2, at \((0.37, 0.40)\), lies at the corner where this sloped edge meets the vertical edge \(x_1 = 0.4\). Point 3, at \((0.39, 0.65)\), lies beside the vertical edge, where only \(x_1\) can change the class. Point 4, at \((0.65, -0.48)\), lies on the lower sloped edge \(x_2 = -1 + 0.8x_1\), where both features can change the class. The same four observations are used in every figure that follows.

Figure 2: The four observations of interest used throughout the paper. The top panel shows the observations in \(\mathcal{D}\) over the feature space, with colour giving the class predicted by the random forest (the faint background is the prediction surface on a dense grid). The numbered black diamonds mark the observations of interest, and the bottom panels zoom in on a \(\pm 0.1\) window around each one. Every observation sits next to a bend or corner of the predicted boundary, so a small change in either feature can change its predicted class.

2.2 The model

The methods in this paper do not depend on the type of model. All that is required is a fitted model \(\hat{f}\) that returns a prediction at any feature vector \(\mathbf{x}\), including values that were not in the training data. As an example, a random forest (Breiman 2001a) with 10 trees was fitted to the training set. A random forest is a well-known model whose training algorithm is simple to state, yet whose fitted function has no closed form that can be read directly, which makes it a typical black box. A small number of trees was used so that the fitted boundary keeps the axis-aligned steps of the individual trees (Figure 3), which creates local non-linearities around the observations of interest. The model classifies 100.0% of the testing set correctly, and agrees with the true class at 99% of the points on a dense grid over the feature space.

2.3 Visualizing the prediction workflow

For the current problem, expanding upon the workflow in Figure 1, there are three primary components,along with one optional baseline,that should be visually inspected together. The optional baseline is the true decision boundary; while rarely available in practice, it can be included in simulated scenarios as a ground truth reference. The three core components consist of the training dataset, visualized to show the data distribution the model learned from; the testing dataset, which demonstrates how the model performs on held out data; and the learned decision surface. This surface represents the model’s predictions generated over a dense, simulated grid encompassing all possible feature values, so that its behavior can be visualized across the entire feature space.

An example is provided in Figure 3 to illustrate how these elements are visually integrated.

Figure 3: Components of the prediction workflow for the two-dimensional example, drawn in the same feature space \((x_1, x_2)\) with colour giving the class: (a) the true class boundary on a dense grid, (b) the training data with observed classes, (c) the testing data with observed classes, and (d) the classes predicted by the random forest on the same grid as (a). Comparing (d) with (a) shows that the model recovers the overall shape of the boundary but replaces the sloped section with axis-aligned steps, which is where local explanations become difficult.

3 Generalizing the workflow for explanations

Previously, the workflow in Figure 1 focused on building a model for prediction. As the objective shifts toward explaining the inner mechanisms of that model, the purpose of an explanation must first be defined. At its core, an explanation should answer a fundamental question: which features were most influential in driving the model’s prediction for a specific observation?

In the modern era, where AI decisions directly impact individuals, understanding these local predictions is paramount. Furthermore, because model decision boundaries often become highly non-linear around difficult or edge-case observations (James et al. 2013), generating individual explanations to map this local behavior is essential. To ensure longevity amid the rapid development of new architectures, this paper focuses exclusively on local interpretability methods that are model-agnostic.

Local explanations are particularly valuable because AI systems increasingly support decisions that directly affect individual people, making observation-specific justification essential. Furthermore, restricting attention to model-agnostic methods ensures that the explanation framework remains applicable regardless of the underlying predictive model, avoiding dependence on architectures that may become obsolete as new machine learning methods emerge.

Compared to the purely predictive pipeline, the explanatory workflow illustrated in Figure 4 introduces several vital components. Beyond the trained model and the input data, the process now incorporates a specific target observation and a customized explanation generated for it. Although existing Explainable AI (XAI) algorithms differ considerably in their exact implementations, they can all be understood through a unified framework consisting of three fundamental stages: a perturbation mechanism, an optimization objective, and a final explanation output.

The process begins with a perturbation mechanism, which generates a simulated collection of synthetic observations in the immediate neighborhood of the target instance. This collection, defined as the local perturbation dataset, maps out the feature space around the specific observation being analyzed. The method of generating these neighbors varies across algorithms, ranging from random local sampling in LIME and feature masking in SHAP, to selective perturbation outside candidate rules in Anchors and optimization-based searches in Counterfactual explanations.

Next, the black-box model evaluates these simulated neighbors to produce local predictions. These outputs are fed into an optimization objective, which aligns the perturbed data and their predictions according to a method-specific criterion. In traditional statistics, parametric models inherently possess a functional form that explicitly outlines the contribution of each predictor. Machine learning models, however, are complex procedural algorithms lacking such transparency. To bridge this gap, the optimization stage frequently involves fitting a simple, interpretable surrogate model—referred to as the local parametric model. Whether it is a generalized linear model (GLM), a ridge regression, or a shallow decision tree, this surrogate mimics the black-box model’s behavior within the local neighborhood. While not every XAI method requires an explicit surrogate model (SHAP computes additive attributions directly, Anchors optimize rules, and Counterfactuals search for alternatives), all rely on applying an optimization criterion to local predictions.

Ultimately, the optimized representation is returned as the final explanation. Depending on the underlying XAI method, this output takes an interpretable form tailored to the user’s needs, such as feature importance coefficients, Shapley values, decision rules, or a modified counterfactual input. Together, these three stages provide a cohesive abstraction for seemingly disparate model-agnostic methods.

flowchart LR
    subgraph Prediction [Prediction workflow]
        A["Dataset 𝒟"] --> B["Training set 𝒟<sub>train</sub>"] --> C["Fitted model f̂"]
    end

    subgraph Explanation [Explanation workflow]
        X["Observation x<sub>i</sub>"] --> P["1. Perturbation<br/>𝒵 near x<sub>i</sub>"]
        P --> Q["Predictions f̂(𝒵)"]
        Q --> O["2. Optimization<br/>criterion over 𝒵, f̂(𝒵)"]
        O --> E["3. Explanation E<sub>i</sub>"]
    end

    C --> Q
Figure 4: The generalized workflow when optimizing for local model explanation. The Prediction workflow panel repeats Figure 1 and supplies the fitted model \(\hat{f}\). The Explanation workflow panel shows the three stages shared by local model-agnostic explainers: perturbations \(\mathcal{Z}\) are drawn around the observation \(\mathbf{x}_i\), scored by \(\hat{f}\), and passed to a method-specific optimization criterion that returns the explanation \(E_i\). The methods differ only in how each stage is filled in (SHAP: feature coalitions and Shapley values; LIME: a weighted sample and surrogate coefficients; counterfactuals: a search for the nearest opposite-class point; Anchors: rule perturbation and a high-precision box), which is what allows their outputs to be drawn in a common geometric space.

4 XAI methods and their geometrical representation

The XAI methods discussed in this paper are built up of the components that can be generalized to contain, a perturbation mechanism, an optimization objective and a final output.

A perturbation mechanism in this context is a method that generates new instances around the local observation through perturbation. Afterwards using perturbed data and the original black box model, each XAI method will try to solve an optimization criteria that is related to the question that the XAI method is trying to answer. The returned output of each XAI method will differ, due to the nature of the question that each method is trying to answer.

The following notation is used throughout the paper. The black box model is written as \(f\), where \(f(\mathbf{x})\) is the model’s predicted probability that an observation with features \(\mathbf{x}\) belongs to class \(A\), and \(\hat{y}(\mathbf{x})\) is the class the model predicts. The observation to be explained is \(\mathbf{x}_i = (x_{i1}, \dots, x_{ip})\), with \(x_{ij}\) the value of feature \(j\).

The perturbation mechanism generates \(M\) new points \(\mathcal{Z} = \{ \mathbf{z}_1, \dots, \mathbf{z}_M \}\) around \(\mathbf{x}_i\), inside a box with lower and upper corners as \(\mathbf{D}_{il} = (D_{i1l}, \dots, D_{ipl})\) and \(\mathbf{D}_{iu} = (D_{i1u}, \dots, D_{ipu})\).

Each XAI method \(m\) returns a \(p\)-dimensional explanation vector for observation \(i\), \[ \mathbf{E}_i^{(m)} = \lbrack E_{i1}^{(m)}, \dots, E_{ip}^{(m)} \rbrack, \qquad m \in \{S=\text{SHAP}, L=\text{LIME}, A=\text{Anchors}, C=\text{Counterfactual}\}, \] where \(E_{ij}^{(m)}\) is the value method \(m\) assigns to feature \(j\).

From the plethora of available local interpretability methods, this paper focuses on SHAP, Counterfactuals, LIME and Anchors as they are model agnostic and therefore can be applied to a wide variety of models (Molnar 2022). These four methods have a similar structure that showcase different aspects of the model such as understanding the influence of features on a given prediction and the model boundary associated around the local neighborhood of the prediction.

4.1 SHAP

SHAP explanations are also model coefficients estimated to show the change in the expected prediction when the model is with and without the given feature. For a given observation, SHAP explanations can be represented as “forces” or unit vectors pulling the observations in the directions of each dimension. While these unit vectors aren’t necessarily pushing the observation to another place, it is a depiction of the influence that each feature is having on the observation.

SHAP splits the model’s prediction for observation \(\mathbf{x}_i\) into \(p\) pieces, one per feature, collected in the explanation vector \(\mathbf{E}_i^{(S)} = \lbrack E_{i1}^{(S)}, \dots, E_{ip}^{(S)} \rbrack\).

Each value \(E_{ij}^{(S)}\) is the amount by which feature \(j\) moves the prediction away from a baseline \(\bar{f_{\mathcal{Z}}}\). The baseline is the average prediction over a set of background points; in this paper these are the perturbed points, \(\bar{f_{\mathcal{Z}}} = \frac{1}{R}\sum_{r=1}^R f(\mathbf{z}_r)\). The key property of SHAP values is that they add up: the baseline plus all \(p\) values gives back the model’s prediction for \(\mathbf{x}_i\),

\[ f(\mathbf{x}_i) = \bar{f_{\mathcal{Z}}} + \sum_{j=1}^{p} E_{ij}^{(S)}. \]

To decide how much of the gap between \(\bar{f_{\mathcal{Z}}}\) and \(f(\mathbf{x}_i)\) belongs to each feature, SHAP fixes the true values of \(\mathbf{x}_i\) one subset of features at a time and insert samples for the other features. Let \(\mathcal{P} = \{1, \dots, p\}\) be the set of all features and \(\mathcal{S} \subseteq \mathcal{P}\) a subset (a coalition) of revealed features. For the two-feature problem (\(p = 2\)), \(\mathcal{P} = \{1, 2\}\) has four subsets, \(\mathcal{S} = \{ {\varnothing}, (\{1\}, \{2\}, \{1,2\} \}\)

Define the value function \(v(\mathcal{S})\) as the average prediction when the features in \(\mathcal{S}\) are fixed at their values in \(\mathbf{x}_i\) and the remaining features are taken from the background points,

\[ v(\mathcal{S}) = \frac{1}{R}\sum_{r=1}^{R} f\big(\mathbf{x}_{i\mathcal{S}}, \mathbf{z}_{r\bar{\mathcal{S}}}\big), \]

where \((\mathbf{x}_{i\mathcal{S}}, \mathbf{z}_{r\bar{\mathcal{S}}})\) is the point whose \(j\)-th coordinate is \(x_{ij}\) if \(j \in \mathcal{S}\) and \(z_{rj}\) otherwise. Here \(\bar{\mathcal{S}}\) refers to the complement of the set.

Therefore the value function takes on the following form.

\[ \begin{aligned} v(\varnothing) &= \frac{1}{R}\sum_{r=1}^{R} f(z_{r1}, z_{r2}) = \bar{f_{\mathcal{Z}}} && \text{(no feature revealed)},\\ v(\{1\}) &= \frac{1}{R}\sum_{r=1}^{R} f(x_{i1}, z_{r2}) && \text{(only feature 1 revealed)},\\ v(\{2\}) &= \frac{1}{R}\sum_{r=1}^{R} f(z_{r1}, x_{i2}) && \text{(only feature 2 revealed)},\\ v(\{1,2\}) &= f(x_{i1}, x_{i2}) = f(\mathbf{x}_i) && \text{(all features revealed)}. \end{aligned} \]

For example, \(v(\{1\})\) is computed by taking every perturbed point \(\mathbf{z}_r\), overwriting its first coordinate with \(x_{i1}\) while keeping its own second coordinate \(z_{r2}\), and averaging the model’s predictions over these \(R\) modified points. The difference \(v(\{1\}) - v(\varnothing)\) is then how much the average prediction changes once feature 1 is revealed.

The change caused by setting feature \(j\) to the actual value depends on which other features are already revealed, so SHAP averages this change over every coalition \(\mathcal{S}\) that does not contain \(j\),

\[ E_{ij}^{(S)} = \sum_{\mathcal{S} \subseteq \mathcal{P} \setminus \{j\}} \frac{|\mathcal{S}|!\,(p - |\mathcal{S}| - 1)!}{p!} \Big[v(\mathcal{S} \cup \{j\}) - v(\mathcal{S})\Big]. \]

With \(p = 2\) the weights are both \(\frac{1}{2}\), so each SHAP value is the average of two differences,

\[ \begin{aligned} E_{i1}^{(S)} &= \frac{1}{2}\Big[v(\{1\}) - v(\varnothing)\Big] + \frac{1}{2}\Big[v(\{1,2\}) - v(\{2\})\Big],\\ E_{i2}^{(S)} &= \frac{1}{2}\Big[v(\{2\}) - v(\varnothing)\Big] + \frac{1}{2}\Big[v(\{1,2\}) - v(\{1\})\Big]. \end{aligned} \]

Adding the two lines gives \(E_{i1}^{(S)} + E_{i2}^{(S)} = v(\{1,2\}) - v(\varnothing) = f(\mathbf{x}_i) - \bar{f_{\mathcal{Z}}}\), which is exactly the additivity property above.

For general \(p\), the Shapley formula needs the value function for all \(2^p\) coalitions, which becomes expensive as \(p\) grows. KernelSHAP (Lundberg and Lee 2017; Mayer and Watson 2024) approximates the Shapley values from a sample of coalitions instead. Since \(p\) is small in this paper, every coalition is enumerated and the SHAP values are computed exactly.

Two features may not be enough to show fully how SHAP behaves. SHAP is designed for models with many features: in general, the value for feature \(j\) averages its marginal contribution over all \(2^{p-1}\) coalitions of the other features, and so summarizes how the feature acts alongside many different subsets of features. With \(p = 2\) the average has only the two terms shown above, and additivity then fixes \(E_{i2}^{(S)} = f(\mathbf{x}_i) - \bar{f_{\mathcal{Z}}} - E_{i1}^{(S)}\), so the two values are not free to vary independently and any interaction between the features is split equally between them. With more features, the value of a feature depends on how it interacts with many subsets of the others, which a two-feature example cannot show.

Intuitively, the SHAP value \(E_{ij}^{(S)}\) measures the contribution of feature \(j\) to the difference between the prediction \(f(\mathbf{x}_i)\) and the baseline \(\bar{f_{\mathcal{Z}}}\). A larger value in magnitude indicates a stronger influence. Values can be positive or negative, which means that the features push the prediction in opposite directions.

4.1.1 Geometric representation of SHAP

From an abstract visual standpoint, a coefficient can be drawn as a force acting upon the model’s prediction itself. The SHAP values are therefore visualized as axis-parallel arrows scaled by the magnitude of each value. The features are assumed to be on a common scale when visualizing.

Figure 5: Geometric representation of SHAP in two dimensions. Each observation of interest (black diamond) carries two axis-parallel arrows, one per feature, whose length and direction give the SHAP value of that feature; the background shows the class predicted by the random forest. The bottom panels zoom in on each observation. Comparing the two arrows at a point shows at a glance which feature SHAP credits most, and whether the features push the prediction in the same or opposite directions.

4.2 LIME

LIME explains the prediction for \(\mathbf{x}_i\) by fitting a simple, interpretable surrogate model \(g\). As this paper focuses on a classification problem, \(g\) is a logistic regression model fitted to the perturbed points. The surrogate model is typically chosen from the family of models \(\mathcal{G}\) containing generalized or linear models such that it mimics the predictions of the black box model \(f\) within \(\mathcal{Z}\) (Ribeiro et al. 2016). The perturbed points \(\mathcal{Z}\) are given a weight \(\pi_{\mathbf{x}_i}(\mathbf{z}_r)\) that is large when \(\mathbf{z}_r\) is close to \(\mathbf{x}_i\) and small when it is far away.

The explanations from LIME are the result of an optimization problem that considers three criteria: a measure for the goodness of fit \(\mathcal{L}(f, g)\) and a measure of complexity. The measure for the goodness of the fit, \(\mathcal{L}(f, g, \pi_{\mathbf{x}_i})\) measures how badly \(g\) reproduces the predictions of \(f\) on the perturbed points, with each point counted according to its weight. Smaller values mean \(g\) is a more faithful copy of \(f\) near \(\mathbf{x}_i\). For the measure of complexity, \(\Omega(g)\) penalizes complicated surrogates, for example a linear model with many non-zero coefficients.

Put together, the surrogate model is then chosen by solving the following optimization problem,

\[ \arg\min_{g \in \mathcal{G}} \mathcal{L}(f, g, \pi_{\mathbf{x}_i}) + \Omega(g). \]

For the local model the predictors are \(\mathbf{z}_r, r = 1, \dots, R\) while the response is the black box model’s predicted probability \(f(\mathbf{z}_r)\). Thereby the link function for the local model \(g\) can be defined as

\[ \log\left(\frac{f(\mathbf{z}_r)}{1 - f(\mathbf{z}_r)}\right) = \beta_0 + \sum_{j=1}^{p} \beta_j z_{rj}, \qquad r = 1, \dots, R. \]

The coefficients are estimated by weighted maximum likelihood, using the weights \(\pi_{\mathbf{x}_i}(\mathbf{z}_r)\), together with a LASSO penalty \(\lambda \sum_{j} |\beta_j|\) that plays the role of \(\Omega(g)\) by shrinking unimportant coefficients towards zero. The LIME explanation is the vector of fitted slopes,

\[ \mathbf{E}_i^{(L)} = \lbrack \hat{\beta}_1, \dots, \hat{\beta}_p \rbrack, \]

so that \(E_{ij}^{(L)} = \hat{\beta}_j\). Because the features are scaled before fitting, the coefficients are on a comparable scale across features.

Intuitively, LIME provides the slopes \(E_{ij}^{(L)} = \hat{\beta}_j\) of a logistic regression that mimics the model near \(\mathbf{x}_i\). Larger values in magnitude indicate more influential features. Positive and negative values indicate that the features operate in opposite directions.

4.2.1 Geometric representation of LIME

The perturbed points \(\mathcal{Z}\) and the predictions for those points by the black box model \(f(\mathcal{Z})\) are both crucial to understand the coefficients given by a LIME explanation. Therefore the existing visualisation of the machine learning model in data space is supplemented by a secondary plot showing a zoomed in version of the local neighborhood and the model’s faithfulness to the original model. The perturbed dataset is built on top of the predictions from the model on the perturbed data. Therefore showing the local model’s faithfulness to the original model is performed by visualising the local model in its respective space.

Figure 6: Geometric representation of LIME in two dimensions. Around each observation of interest (black diamond) the perturbed points \(\mathcal{Z}\) are drawn and coloured by the class predicted by the local surrogate model, over the faint prediction surface of the random forest. The bottom panels zoom in on each neighbourhood. Where the colour split among the perturbed points matches the background, the surrogate is faithful to the model; where it does not, the LIME coefficients describe a boundary the model does not have.

Following Figure 4, the plot shows the local perturbation dataset used to fit the local model. The lighter shade of colors are the predicted values from the model and then the deeper shade of colors are the predictions from the local model on the perturbation dataset.

To interpret the LIME results, the local model’s boundary has to be considered as an indication of which features were most important for the local model. Intuitively, drawing a line from the point of interest in the direction orthogonal to the local model’s decision boundary would give an indication of which features are more important.

4.3 Counterfactuals

A counterfactual for observation \(\mathbf{x}_i\) is a point \(\mathbf{c}_i = (c_{i1}, \dots, c_{ip})\) that the model assigns to a different class, while being as close as possible to \(\mathbf{x}_i\). It answers the question: “what is the smallest change to the features that would flip the model’s prediction?” In other words, it shows where \(\mathbf{x}_i\) would need to move to cross the model’s decision boundary.

There are many methods of generating counterfactual explanations. This paper uses the What-If approach (Wexler et al. 2020), as implemented in the counterfactuals R package (Dandl et al. 2023), because its process is the most intuitive: rather than synthesizing a new point, it searches the observed data for the nearest observation that the model already classifies differently. Let \(y_i^{*}\) be the desired class, the class other than \(\hat{y}(\mathbf{x}_i)\), and let \(f_{y_i^{*}}(\mathbf{x})\) be the predicted probability that the model assigns to class \(y_i^{*}\). The set of candidate counterfactuals is the set of observations in the training set \(\mathcal{D}_{\text{train}}\) that the model places in the desired class,

\[ \mathcal{C}_i = \left\{ \mathbf{x}_k \in \mathcal{D}_{\text{train}} : f_{y_i^{*}}(\mathbf{x}_k) \geq 0.5 \right\}. \]

The counterfactual is the candidate closest to \(\mathbf{x}_i\),

\[ \mathbf{c}_i = \arg\min_{\mathbf{x}_k \in \mathcal{C}_i} d_G(\mathbf{x}_k, \mathbf{x}_i), \]

where closeness is measured by the Gower distance (Gower 1971)

\[ d_G(\mathbf{x}_k, \mathbf{x}_i) = \frac{1}{p} \sum_{j=1}^{p} \frac{|x_{kj} - x_{ij}|}{R_j}, \]

and \(R_j\) is the range of feature \(j\) in \(\mathcal{D}_{\text{train}}\). Dividing by \(R_j\) puts every feature on a common scale, so that no single feature dominates the distance simply because it is measured in larger units.

Because the What-If approach only searches observed data, the counterfactual it returns depends on where the observations happen to lie. Other implementations search a grid or a simulated sample of points together with the model’s predictions at them, or optimize directly for a new point close to \(\mathbf{x}_i\) (Wachter et al. 2018; Dandl et al. 2020). These can return substantially different counterfactuals for the same observation, typically much closer to the model’s boundary, and so a different direction and a different explanation.

Because \(\mathbf{c}_i\) is drawn from \(\mathcal{D}_{\text{train}}\), it is guaranteed to be a realistic point that has actually been observed. The trade-off is that it is the nearest observed point across the boundary rather than the nearest possible point, so the change it suggests may be larger than strictly necessary, particularly where the data are sparse near the decision boundary.

The values returned for a counterfactual reflect the distance to get from \(\mathbf{x}_i\) to its counterfactual \(\mathbf{c}_i\) along each feature, \(c_{ij} - x_{ij}\). A smaller value would indicate more influence, because changing the value of that feature by a small amount could lead to a change of predicted class. Differing signs are meaningful, in the same way as for the other explainers, indicating that the features operate in opposite directions.

4.3.1 Geometric representation of Counterfactuals

Figure 7: Geometric representation of counterfactuals in two dimensions. Each observation of interest (black diamond) is joined by a line segment to its counterfactual (crossed diamond), the nearest point found on the other side of the predicted boundary; the background shows the class predicted by the random forest. The bottom panels zoom in on each segment. The direction of the segment shows which features must change to flip the prediction, and its length shows how far the observation is from the boundary.

A Counterfactual explanation is another data point itself. Because the What-If approach selects the counterfactual from the observed data, the point already exists in the dataset \(\mathcal{D}\), and it can be highlighted among the plotted observations rather than drawn as a new point. It may also help to show that the model boundary is somewhere along the line connecting the observation and the counterfactual. The exact location of the model boundary is usually unknown, and finding the exact location would not be trivial. But counterfactuals provide a reasonable guesstimate of where the model boundary would lie.

4.4 Anchors

An anchor is a simple “if-then” rule that contains \(\mathbf{x}_i\) and that, when it holds, almost guarantees the model makes the same prediction as it does for \(\mathbf{x}_i\). The rule is built from conditions on individual features, such as \(x_{i1} > 0.2\). For numeric features like ours, combining one such condition per feature gives a box around \(\mathbf{x}_i\),

\[ \mathcal{A}_i = \{\mathbf{z} : A_{ijl} \le z_j \le A_{iju} \text{ for } j = 1, \dots, p\}, \]

where \(A_{ijl}\) and \(A_{iju}\) are the lower and upper limits of the anchor for feature \(j\). A good anchor has two properties, both measured using perturbed points \(\mathbf{z}\) drawn from the neighborhood box \([\mathbf{D}_{il}, \mathbf{D}_{iu}]\) around \(\mathbf{x}_i\).

Precision is the probability that a point inside the anchor gets the same predicted class as \(\mathbf{x}_i\),

\[ \text{Prec}(\mathcal{A}_i) = P\big(\hat{y}(\mathbf{z}) = \hat{y}(\mathbf{x}_i) \mid \mathbf{z} \in \mathcal{A}_i\big). \]

It is estimated by the proportion of perturbed points inside the box that share the prediction of \(\mathbf{x}_i\). A high precision means the box is “pure”.

Coverage is the probability that a perturbed point falls inside the anchor,

\[ \text{Cov}(\mathcal{A}_i) = P(\mathbf{z} \in \mathcal{A}_i), \]

estimated by the proportion of perturbed points that lie inside the box. A high coverage means the rule applies to a large part of the neighborhood.

The two properties pull in opposite directions: a tiny box around \(\mathbf{x}_i\) is usually very pure but covers almost nothing. Anchors resolves this by finding the box with the largest coverage among those that are pure enough. Because precision is estimated from a sample, it is required to exceed a chosen threshold \(\tau\) (e.g. \(0.95\)) with high confidence, where \(\delta\) (e.g. \(0.05\)) is the accepted probability that this does not hold:

\[ \max_{\mathcal{A}_i} \ \text{Cov}(\mathcal{A}_i) \quad \text{subject to} \quad P\big(\text{Prec}(\mathcal{A}_i) \ge \tau\big) \ge 1 - \delta. \]

Intuitively, the anchor values compare the side lengths of the anchor box \(\mathcal{A}_i\) with those of the neighborhood box. A smaller relative side length indicates a more influential feature, because the box can only be extended a small amount in that direction, to get a more pure box.

4.4.1 Geometric representation of Anchors

Anchors are defined as a list of boundary conditions. These boundary conditions should be represented as a \(p\)-dimensional hypercube in the data space. For two dimensions the boundary would be a square while for high dimensions the generated boundary would be a \(p\)-dimensional hypercube. However, simply drawing a cube would not suffice to communicate a key information that Anchors provides: a majority of the area within the cube would contain points that have a similar outcome to the given observation. Therefore it is necessary to highlight the contents of the box compared to the points outside the box.

Figure 8: Geometric representation of Anchors in two dimensions. For each observation of interest (black diamond) the anchor rule is drawn as a dark box, and the grey outlined box shows the region in which perturbations were drawn; points are coloured by class. The bottom panels zoom in on each anchor. A good anchor is a box whose contents are almost all of the observation’s predicted class, so the mix of colours inside the box shows how precise the rule is.

5 Disagreements

The four methods return explanations in different forms. SHAP returns an additive attribution for each feature, LIME the coefficients of a local surrogate model, counterfactuals a new data point across the model’s boundary (or equivalently the change in each feature needed to reach it), and Anchors a box of feature ranges within which most points share the prediction for the observation. These explanations are therefore not directly comparable, as they measure different facets of the underlying model’s behavior. SHAP and LIME give attribution scores, while counterfactuals and Anchors rely on spatial quantities: the distance from the observation to its counterfactual, and the distances from the observation to the edges of the anchor box.

5.1 Extracting and standardizing information from explanations

Recall from Section 4 that \(\mathbf{E}_i^{(m)}\) denotes the \(p\)-dimensional explanation vector for observation \(i\) using method \(m\), where \(m \in \{S=\text{SHAP}, L=\text{LIME}, A=\text{Anchors}, C=\text{Counterfactual}\}\).

SHAP and LIME (\(m \in \{S, L\}\))

For SHAP (\(m=S\)) and LIME (\(m=L\)), the explanation vectors are defined respectively as the SHAP values and the fitted logistic regression slopes (Section 4.1 and Section 4.2). For SHAP with more than two features, each value \(E_{ij}^{(S)}\) is a weighted average of the marginal contribution of feature \(j\) over every coalition of the other features, which is the same as averaging over every order in which the features could be added to the model. The value therefore does not depend on any single order, and the additivity property, \(\sum_{j} E_{ij}^{(S)} = f(\mathbf{x}_i) - \bar{f_{\mathcal{Z}}}\), holds for any \(p\):

\[ \mathbf{E}_i^{(S)} = \lbrack E_{i1}^{(S)}, \dots, E_{ip}^{(S)} \rbrack \]

\[ \mathbf{E}_i^{(L)} = \lbrack E_{i1}^{(L)}, \dots, E_{ip}^{(L)} \rbrack \]

Anchors (\(m=A\))

Let \(\mathbf{D}_{iu}\) and \(\mathbf{D}_{il}\) be the upper and lower bounds of the perturbation distribution, and let \(\mathbf{A}_{iu} = (A_{i1u}, \dots, A_{ipu})\) and \(\mathbf{A}_{il} = (A_{i1l}, \dots, A_{ipl})\) be the corresponding upper and lower bounds of the anchor \(\mathcal{A}_i\). Each entry below is one minus the fraction of the neighborhood’s width that the anchor covers along feature \(j\), so a narrower anchor gives a larger value. The explanation vector is:

\[ \mathbf{E}_i^{(A)} = \left\lbrack 1 - \frac{A_{i1u} - A_{i1l}}{D_{i1u} - D_{i1l}}, \dots, 1 - \frac{A_{ipu} - A_{ipl}}{D_{ipu} - D_{ipl}} \right\rbrack \]

Counterfactuals (\(m=C\))

Let \(\mathbf{x}_i\) be the observation of interest and \(\mathbf{c}_i\) be its corresponding counterfactual observation. The displacement vector between them is \(\mathbf{d}_i = \mathbf{c}_i - \mathbf{x}_i\).

The angle \(\theta_j\) between the displacement vector \(\mathbf{d}_i\) and the standard basis vector \(\mathbf{e}_j\) determines how directly the counterfactual moves along feature axis \(j\). The cosine of this angle is calculated using their dot product and magnitudes:

\[ \cos(\theta_j) = \frac{\mathbf{d}_i \cdot \mathbf{e}_j}{\Vert\mathbf{d}_i\Vert_2 \Vert\mathbf{e}_j\Vert_2} = \frac{c_{ij} - x_{ij}}{\Vert\mathbf{c}_i - \mathbf{x}_i\Vert_2} \]

The counterfactual explanation vector is thereby set as:

\[ \mathbf{E}_i^{(C)} = \left\lbrack \left|\frac{c_{i1} - x_{i1}}{\Vert\mathbf{c}_i - \mathbf{x}_i\Vert_2}\right|, \dots, \left|\frac{c_{ip} - x_{ip}}{\Vert\mathbf{c}_i - \mathbf{x}_i\Vert_2}\right| \right\rbrack \]

Feature Importance Normalization

To put the explanations from all methods on a common scale, the absolute value of each entry is divided by the largest absolute entry for that observation and method. This gives normalized feature importance scores \(I_{ij}^{(m)} \in [0, 1]\), where the most important feature always scores 1, for any method \(m \in \{S,L,A,C\}\):

\[ I_{ij}^{(m)} = V(E_{ij}^{(m)}) = \frac{\vert{}E_{ij}^{(m)}\vert{}}{\max_{k = 1, \dots, p} \vert{}E_{ik}^{(m)}\vert{}} \]

Table 1: Explanations from SHAP, LIME, Anchors and counterfactuals at the four observations of interest. Each row is one observation. The Model column shows the training observations and the predicted class surface around \(\mathbf{x}_i\), the glyphs show each method’s geometric representation in the same space, the Raw explanation columns give each method’s output as usually reported, and the Normalized importance columns give \(I_{ij}^{(m)}\), where the most important feature scores 1. The explainers agree at Point 3, where only \(x_1\) can change the prediction, but disagree on which feature matters most elsewhere, most clearly at Points 2 and 4.
Point Model Method Explanation
Raw explanation E
Normalized importance I
x₁ x₂ x₁ x₂
1 LIME −38.20 94.74 0.40 1.00
SHAP 0.14 0.32 0.43 1.00
Counterfactuals 0.37 0.93 0.40 1.00
Anchors 0.20 0.40 0.50 1.00
2 LIME −69.30 56.99 1.00 0.82
SHAP −0.14 −0.06 1.00 0.47
Counterfactuals 0.58 −0.82 0.71 1.00
Anchors 0.45 0.40 1.00 0.89
3 LIME −1001.34 0.00 1.00 0.00
SHAP −0.48 0.00 1.00 0.00
Counterfactuals 0.98 0.20 1.00 0.21
Anchors 0.45 0.00 1.00 0.00
4 LIME 70.09 −86.70 0.81 1.00
SHAP −0.16 −0.15 1.00 0.94
Counterfactuals −0.99 0.13 1.00 0.13
Anchors 0.33 0.45 0.74 1.00

Table 1 collects the explanations for the four observations of interest. For each point, the Model column shows a close-up of the fitted model’s predicted class surface around \(\mathbf{x}_i\) (black diamond), with the nearby training observations overlaid. Each row then gives one method’s glyph, drawn on the same close-up. The LIME glyph shows the perturbed samples coloured by the local surrogate’s prediction, so the split between colours is the surrogate’s linear boundary. The SHAP glyph draws an arrow from \(\mathbf{x}_i\) along each axis, with length equal to that feature’s Shapley value. The counterfactual glyph joins \(\mathbf{x}_i\) to its counterfactual \(\mathbf{c}_i\) (hollow diamond) in the opposite class. The Anchors glyph shows the anchor rule as a dark rectangle inside the grey perturbation box: the more tightly the anchor is bounded along a feature, the more that feature matters. The Raw explanation columns give \(E_{ij}^{(m)}\), which sit on very different scales across methods (LIME coefficients run into the hundreds, while counterfactual components lie in \([-1, 1]\)). The Normalized importance columns give \(I_{ij}^{(m)}\), where a value of 1 marks the feature the method ranks first.

The four points tell different stories. Point 3 sits beside a vertical stretch of the boundary, so only \(x_1\) can change the prediction. Every method agrees: LIME, SHAP and Anchors give \(x_2\) an importance of exactly 0, and the counterfactual moves almost entirely along \(x_1\). At Points 1 and 2 the counterfactual disagrees with the rest. At Point 1, LIME, SHAP and Anchors rank \(x_2\) first, while the counterfactual crosses the boundary mainly along \(x_1\). At Point 2, which lies at a corner of the boundary, LIME and SHAP rank \(x_1\) first and Anchors gives the two features equal importance, while the counterfactual moves mainly down in \(x_2\), because the nearest observation of the other class lies below and only slightly to the side of the point. Point 4 splits the methods into two pairs: LIME and Anchors favour \(x_2\), while SHAP and the counterfactual favour \(x_1\). SHAP does so only by a small margin (\(I =\) 0.94 for \(x_2\)). Near-ties such as this, and LIME’s 0.82 for \(x_2\) at Point 2, show that a method’s top feature can depend on a small difference in scores. Agreement on which feature ranks first therefore does not establish which explanation to trust, which is addressed in Section 5.2.

5.2 Assessing the reliability of explainers

5.2.1 Defining metrics for reliability

The normalized importances \(I_{ij}^{(m)}\) defined in Section 5.1 make the explainers comparable, but they do not show which explainer gives the most reliable account of the model at \(\mathbf{x}_i\). Reliability is assessed on two criteria: truthfulness, whether the features an explainer marks as important really drive the model’s behavior, and sensitivity, whether the explanation stays stable when \(\mathbf{x}_i\) changes by a negligible amount.

Truthfulness

Let \(\mathcal{J}_i^{(m)} \subseteq \{1, \dots, p\}\) be the set of features that method \(m\) marks as important for observation \(i\). If these features really drive the prediction, then observations that share the values of \(\mathbf{x}_i\) on \(\mathcal{J}_i^{(m)}\) should share the class predicted for \(\mathbf{x}_i\), whatever their values on the remaining features. Perturbed points cannot be used for this check, because their true class is only known when the decision boundary is known. Instead, the training observations \(\mathcal{D}_{\text{train}} \subseteq \mathcal{D}\), whose classes \(y_k\) are observed, are used, keeping those that fall inside the neighborhood box of \(\mathbf{x}_i\),

\[ \mathcal{N}_i = \big\{ k : (\mathbf{x}_k, y_k) \in \mathcal{D}_{\text{train}},\; \mathbf{D}_{il} \le \mathbf{x}_k \le \mathbf{D}_{iu} \big\}, \]

and measure how close each one is to \(\mathbf{x}_i\) on the important features only, using a weighting function \(w_k^{(m)}\). Observations that match \(\mathbf{x}_i\) on the important features get weights near 1, regardless of how they differ on the other features. The truthfulness of method \(m\) at observation \(i\) is the weighted share of these observations whose observed class agrees with the prediction at \(\mathbf{x}_i\):

\[ T_i^{(m)} = \frac{\sum_{k \in \mathcal{N}_i} w_k^{(m)}\, \mathbb{1}\big[y_k = \hat{y}(\mathbf{x}_i)\big]} {\sum_{k \in \mathcal{N}_i} w_k^{(m)}} \in [0, 1]. \]

For \(p = 2\), if SHAP marks feature 1 as important, training observations in the box with \(x_{k1}\) close to \(x_{i1}\) get the most weight, whatever their value of \(x_{k2}\). \(T_i^{(S)}\) is then the weighted share of these observations that carry the class predicted for \(\mathbf{x}_i\).

A larger \(T_i^{(m)}\) means that knowing only the features chosen by method \(m\) is enough to recover the predicted class from real, labeled data around \(\mathbf{x}_i\). The same score computed with the complementary features \(\bar{\mathcal{J}}_i^{(m)}\) serves as a reference: a truthful explainer should score higher on the features it selects than on the ones it ignores. The score relies on \(\mathcal{N}_i\) containing enough training observations. When the box is sparse, \(\mathcal{N}_i\) can be replaced by the \(K\) nearest training observations to \(\mathbf{x}_i\).

Sensitivity

A reliable explanation should not change much under a tiny perturbation of the input. \(B\) jittered copies of the observation are drawn,

\[ \mathbf{x}_i^{(b)} = \mathbf{x}_i + \boldsymbol{\varepsilon}_b, \qquad \boldsymbol{\varepsilon}_b \sim \text{Uniform}(-\delta, \delta)^p, \qquad b = 1, \dots, B, \]

with \(\delta\) very small (for example \(\delta = 10^{-5}\)). Let \(\mathbf{I}_i^{(m)}\) be the vector of normalized importances at \(\mathbf{x}_i\) and \(\mathbf{I}_i^{(m,b)}\) the vector at \(\mathbf{x}_i^{(b)}\). The sensitivity of method \(m\) is the average change in importance:

\[ S_i^{(m)} = \frac{1}{B} \sum_{b=1}^{B} \frac{1}{p} \big\Vert \mathbf{I}_i^{(m,b)} - \mathbf{I}_i^{(m)} \big\Vert_1 \in [0, 1]. \]

Because each \(I_{ij}^{(m)} \in [0, 1]\), \(S_i^{(m)} = 0\) means the explanation does not change at all, and values near 1 mean it changes completely.

Reliability

An explainer is reliable at \(\mathbf{x}_i\) when its truthfulness \(T_i^{(m)}\) is high and its sensitivity \(S_i^{(m)}\) is low. The two scores are reported side by side, \(\big(T_i^{(m)}, S_i^{(m)}\big)\), rather than merging them into one number, so that a method that is truthful but unstable can be told apart from one that is stable but misleading.

5.2.2 Evaluation

Table 2 reports both scores for the four observations of interest. For truthfulness, \(\mathcal{J}_i^{(m)}\) is the feature with normalized importance 1, the neighborhood box is the one used by LIME, SHAP and Anchors, and \(w_k^{(m)}\) is a Gaussian kernel on the important features with a bandwidth of one tenth of the box width.

The column T (other) is the reference score computed on the complementary feature, so that when \(x_2\) is marked as important, T (other) treats \(x_1\) as important instead. Sensitivity is computed over a \(11 \times 11\) grid of jittered copies of \(\mathbf{x}_i\) (\(B = 121\)) at two step sizes, \(\delta = 10^{-4}\) and \(\delta = 10^{-3}\).

Table 2: Truthfulness and sensitivity of each explainer at the four observations of interest. Each row is one observation and each column group one explainer. T is the truthfulness score defined in Section 5.2 and T (other) the same score computed with the complementary feature treated as important; S measures how much the explanation changes under a negligible jitter of \(\mathbf{x}_i\). A truthful explainer has T above T (other), and a stable explainer has S close to 0.
Point Method Important feature
Truthfulness
Sensitivity S
T T (other) δ = 10-4 δ = 10-3
1 LIME x₂ 0.51 0.58 0.05 0.06
SHAP x₂ 0.51 0.58 0.00 0.03
Counterfactuals x₂ 0.51 0.58 0.51 0.44
Anchors x₂ 0.51 0.58 0.06 0.07
2 LIME x₁ 0.52 0.40 0.01 0.02
SHAP x₁ 0.52 0.40 0.00 0.05
Counterfactuals x₂ 0.40 0.52 0.01 0.18
Anchors x₁ 0.52 0.40 0.00 0.04
3 LIME x₁ 0.88 0.52 0.00 0.00
SHAP x₁ 0.88 0.52 0.00 0.00
Counterfactuals x₁ 0.88 0.52 0.00 0.04
Anchors x₁ 0.88 0.52 0.00 0.00
4 LIME x₂ 0.55 0.49 0.00 0.01
SHAP x₁ 0.49 0.55 0.01 0.07
Counterfactuals x₁ 0.49 0.55 0.00 0.23
Anchors x₂ 0.55 0.49 0.09 0.12

With \(p = 2\) every explainer names either \(x_1\) or \(x_2\), so explainers that agree on the important feature share the same truthfulness score, and the comparison reduces to which feature each explainer picks. At Point 3 all four explainers name \(x_1\), and the training data back this up: knowing \(x_1\) alone recovers the predicted class for 88% of the nearby observations, against about half when only \(x_2\) is known. At the other three points the explainers disagree, and truthfulness separates them. At Point 1 the labeled data favour \(x_1\) (0.58 against 0.40), which only the counterfactual names; LIME, SHAP and Anchors all name \(x_2\). At Point 2 the counterfactual moves mainly along \(x_2\), but the data favour \(x_1\) (0.52 against 0.40), which LIME and SHAP name. Anchors gives both features equal importance at Point 2 and scores lowest, 0.39, because requiring a match on both features is the strictest test. At Point 4 the data favour \(x_2\), the feature named by LIME and Anchors, over \(x_1\), the feature named by SHAP and the counterfactual, but only narrowly (0.55 against 0.49), and SHAP’s own importances for the two features are nearly equal (0.94 against 1).

At \(\delta = 10^{-4}\), LIME, SHAP and the counterfactual are stable, with \(S\) below 0.02 everywhere, so they do not react to changes in the input that are of no practical size. Anchors is the exception, with \(S\) of 0.06 at Point 2 and 0.09 at Point 4, where even a negligible shift moves the edges of the anchor box. At \(\delta = 10^{-3}\) the explainers separate further. Counterfactuals change the most at Points 1, 2 and 4, with \(S\) between 0.17 and 0.23, because the nearest observation of the opposite class changes as the input moves, which turns the direction of the displacement vector. Anchors change next most at Point 4. LIME and SHAP stay stable at both step sizes, which is expected since they average the model over the whole neighborhood.

Taken together, LIME is the most reliable explainer at these points: it names the feature with the higher truthfulness at three of the four points and is the most stable at both step sizes. Counterfactuals are the least reliable: they name the less truthful feature at Points 2 and 4 and are the most sensitive to jitter, although they are the only explainer to name the more truthful feature at Point 1.

6 Discussion

An explanation is usually read on its own, as a bar chart of feature contributions or a table of numbers. This paper treats it instead as the last layer of a pipeline: the data, the model’s predictions on that data, the perturbations drawn around the observation, the optimization that turns the perturbations into an explanation, and finally the explanation itself (Figure 4). Table 1 is laid out to follow this pipeline from left to right. The Model column shows the first two layers, the training observations and the model’s predicted class surface around \(\mathbf{x}_i\). The glyphs add the perturbation and optimization layers, drawn in the same data space. The Raw explanation columns give the output of each method as it is usually reported. The Normalized importance columns put the outputs on a common scale so that they can be compared. Table 2 then goes back to the first layer and checks each explanation against the labeled data.

Reading the table in this order shows where two explainers part ways, not only that their final outputs disagree. The Model column already explains the agreement at Point 3, where the boundary near \(\mathbf{x}_i\) is vertical and only \(x_1\) can change the prediction, and the disagreement at Point 2, which sits at a corner of the boundary. The glyphs locate the disagreement in the layers that follow. The counterfactual answers a different question from the other methods: it follows the shortest path to the opposite class, so its direction depends on where the nearest observation of that class happens to lie, which is also why it changes the most under jitter at Points 1, 2 and 4. SHAP and LIME share the same neighborhood but optimize different criteria. SHAP credits the value \(x_{ij}\) relative to the neighborhood average, while LIME fits the slope of the local boundary, which is why they split at Point 4. The Raw explanation columns hide these reasons, because the methods report on scales that differ by orders of magnitude. The Normalized importance columns make the methods comparable, but they reduce each explanation to a ranking, and a ranking can turn on a near-tie.

None of the representations is tied to the plane. Each is a set of points, segments and flat pieces in \(\mathbb{R}^p\): \(p\) axis-parallel arrows for SHAP, a \((p-1)\)-dimensional hyperplane for LIME, a segment for the counterfactual and a hyperrectangle for Anchors. A linear projection maps points to points, segments to segments and flat pieces to flat pieces, so the explanation can be appended to the data and projected with it. The layers of Table 1 can therefore be drawn in higher dimensions with a tour (Asimov 1985; Cook et al. 1995), which shows the data through a smooth sequence of two-dimensional projections (Wickham et al. 2011; Hart and Wang 2025). A four-dimensional extension of the example (Supplementary material) adds a feature \(x_3\) that shears the decision boundary and a noise feature \(x_4\). Because the rule is known, the extra features act as checks that two dimensions cannot provide. LIME tilts its hyperplane along \(x_3\) wherever the boundary depends on it and gives \(x_4\) no weight. SHAP gives \(x_3\) almost no weight at points where the model depends on it, for the same reason it disagrees with LIME at Point 4. The counterfactual segments gain a large component along the noise feature, because the same number of observations spread over four dimensions leaves the nearest observation of the opposite class far from \(\mathbf{x}_i\).

Moving to higher dimensions has limitations. A single projection no longer shows everything. A SHAP arrow or a counterfactual segment looks short when its feature faces away from the viewer, a LIME hyperplane fills the view unless the projection contains its normal vector, and an anchor hyperrectangle hides its short sides in most views. Static figures therefore need a chosen view, for example a projection pursuit view of the local model boundary, or the plane spanned by the two features with the largest \(I_{ij}^{(m)}\). The cost also grows with \(p\): a perturbation grid grows exponentially in \(p\), and a hyperrectangle has \(p\,2^{p-1}\) edges. Tours remain practical up to 10 to 20 features (Lee et al. 2022). Beyond that the features must first be reduced, for example by principal components or by keeping the features that any explainer ranks highly.

Two further limitations concern the scope of the methods. First, the counterfactuals in this paper are free to change any feature, so the segment always points to the nearest observation of the opposite class. In practice only some features can be changed: a person can change their income but not their age, and some changes are only possible in one direction. Restricting the search to actionable features (Ustun et al. 2019) would change both the segment and the importance derived from it, and the geometric representation would then need to show the features that were held fixed, for example as a constrained subspace through \(\mathbf{x}_i\). Second, the representations are defined for classification. SHAP, LIME and counterfactual methods apply equally to regression, but the class boundary that every glyph is drawn against has no direct counterpart for a continuous response, and extending the representations to regression, for example by drawing explanations against contours of the prediction surface, is left for future work.

These limits point to the need for interactivity, in two dimensions as well as in higher ones. Table 1 is a fixed set of small multiples for four points chosen in advance, and the choice of points is itself a decision that shapes what the reader sees. An interactive display would let the user select any observation and see its row of the table, switch each layer of the pipeline on and off, change the size of the neighborhood or the jitter step \(\delta\) and watch the explanations and the reliability scores respond. In higher dimensions the user also needs to steer the projection, by moving between a grand tour, a guided tour towards the local boundary, a local tour around it and a slice through \(\mathbf{x}_i\) (Ursula Laa and Valencia 2020), with the table linked to the view. Such a display adds the last layer that Figure 4 leaves out, the person reading the explanation. It lets them explore each layer of the pipeline instead of relying on a fixed set of views, and bring their own knowledge of the data to decide which explanation to trust.

References

Ali, Sajid, Tamer Abuhmed, Shaker El-Sappagh, et al. 2023. “Explainable Artificial Intelligence (XAI): What We Know and What Is Left to Attain Trustworthy Artificial Intelligence.” Information Fusion 99: 101805. https://doi.org/https://doi.org/10.1016/j.inffus.2023.101805.
Apley, Daniel W, and Jingyu Zhu. 2020. “Visualizing the Effects of Predictor Variables in Black Box Supervised Learning Models.” Journal of the Royal Statistical Society Series B: Statistical Methodology 82 (4): 1059–86.
Arel-Bundock, Vincent, Noah Greifer, and Andrew Heiss. 2024. “How to Interpret Statistical Models Using marginaleffects for R and Python.” Journal of Statistical Software 111 (9): 1–32. https://doi.org/10.18637/jss.v111.i09.
Asimov, Daniel. 1985. “The Grand Tour: A Tool for Viewing Multidimensional Data.” SIAM Journal on Scientific and Statistical Computing 6 (1): 128–43. https://doi.org/10.1137/0906011.
Baniecki, Hubert, and Przemyslaw Biecek. 2019. “modelStudio: Interactive Studio with Explanations for ML Predictive Models.” Journal of Open Source Software 4 (43): 1798. https://doi.org/10.21105/joss.01798.
Baniecki, Hubert, Dariusz Parzych, and Przemyslaw Biecek. 2023. “The Grammar of Interactive Explanatory Model Analysis.” Data Mining and Knowledge Discovery, 1–37. https://doi.org/10.1007/s10618-023-00924-w.
Breiman, Leo. 2001a. “Random Forests.” Machine Learning 45 (1): 5–32. https://doi.org/10.1023/A:1010933404324.
Breiman, Leo. 2001b. “Statistical Modeling: The Two Cultures.” Statistical Science 16 (3): 199–231. https://doi.org/10.1214/ss/1009213726.
Cook, Dianne, Andreas Buja, Javier Cabrera, and Catherine Hurley. 1995. “Grand Tour and Projection Pursuit.” Journal of Computational and Graphical Statistics 4 (3): 155–72.
Dandl, Susanne, Andreas Hofheinz, Martin Binder, Bernd Bischl, and Giuseppe Casalicchio. 2023. Counterfactuals: An R Package for Counterfactual Explanation Methods. arXiv. https://doi.org/10.48550/arXiv.2304.06569.
Dandl, Susanne, Christoph Molnar, Martin Binder, and Bernd Bischl. 2020. “Multi-Objective Counterfactual Explanations.” Parallel Problem Solving from Nature – PPSN XVI, Lecture notes in computer science, vol. 12269: 448–69. https://doi.org/10.1007/978-3-030-58112-1_31.
Fisher, Aaron, Cynthia Rudin, and Francesca Dominici. 2019. “All Models Are Wrong, but Many Are Useful: Learning a Variable’s Importance by Studying an Entire Class of Prediction Models Simultaneously.” Journal of Machine Learning Research 20 (177): 1–81.
Friedman, Jerome H. 2001. “Greedy Function Approximation: A Gradient Boosting Machine.” Annals of Statistics, 1189–232.
Gower, J. C. 1971. “A General Coefficient of Similarity and Some of Its Properties.” Biometrics 27 (4): 857–71. https://doi.org/10.2307/2528823.
Greenwell, Brandon M et al. 2017. “Pdp: An r Package for Constructing Partial Dependence Plots.” R J. 9 (1): 421.
Hart, Casper, and Earo Wang. 2025. Detourr: Portable and Performant Tour Animations. https://casperhart.github.io/detourr/.
James, Gareth, Daniela Witten, Trevor Hastie, Robert Tibshirani, et al. 2013. An Introduction to Statistical Learning. Vol. 112. Springer.
Lee, Stuart, Dianne Cook, Natalia da Silva, et al. 2022. “The State-of-the-Art on Tours for Dynamic Visualization of High-Dimensional Data.” WIREs Computational Statistics 14 (4): e1573. https://doi.org/10.1002/wics.1573.
Lundberg, Scott M, and Su-In Lee. 2017. “A Unified Approach to Interpreting Model Predictions.” Advances in Neural Information Processing Systems 30.
Mayer, Michael, and David Watson. 2024. Kernelshap: Kernel SHAP. https://github.com/ModelOriented/kernelshap.
Molnar, Christoph. 2022. Interpretable Machine Learning: A Guide for Making Black Box Models Explainable. Second edition. Christoph Molnar.
Molnar, Christoph, Giuseppe Casalicchio, and Bernd Bischl. 2020. Interpretable Machine Learning – A Brief History, State-of-the-Art and Challenges. Vol. 1323. http://arxiv.org/abs/2010.09337.
Olah, Chris, Alexander Mordvintsev, and Ludwig Schubert. 2017. “Feature Visualization.” Distill 2 (11): e7.
Ribeiro, Marco Tulio, Sameer Singh, and Carlos Guestrin. 2016. "Why Should I Trust You?": Explaining the Predictions of Any Classifier. https://doi.org/10.48550/ARXIV.1602.04938.
Ribeiro, Marco Tulio, Sameer Singh, and Carlos Guestrin. 2018. “Anchors: High-Precision Model-Agnostic Explanations.” Proceedings of the AAAI Conference on Artificial Intelligence 32 (1). https://doi.org/10.1609/aaai.v32i1.11491.
Simonyan, Karen, Andrea Vedaldi, and Andrew Zisserman. 2013. “Deep Inside Convolutional Networks: Visualising Image Classification Models and Saliency Maps.” arXiv Preprint arXiv:1312.6034.
Ursula Laa, Dianne Cook, and German Valencia. 2020. “A Slice Tour for Finding Hollowness in High-Dimensional Data.” Journal of Computational and Graphical Statistics 29 (3): 681–87. https://doi.org/10.1080/10618600.2020.1777140.
Ustun, Berk, Alexander Spangher, and Yang Liu. 2019. “Actionable Recourse in Linear Classification.” Proceedings of the Conference on Fairness, Accountability, and Transparency, 10–19. https://doi.org/10.1145/3287560.3287566.
Wachter, Sandra, Brent Mittelstadt, and Chris Russell. 2018. Counterfactual Explanations Without Opening the Black Box: Automated Decisions and the GDPR. arXiv. http://arxiv.org/abs/1711.00399.
Wexler, James, Mahima Pushkarna, Tolga Bolukbasi, Martin Wattenberg, Fernanda Viégas, and Jimbo Wilson. 2020. “The What-If Tool: Interactive Probing of Machine Learning Models.” IEEE Transactions on Visualization and Computer Graphics 26 (1): 56–65. https://doi.org/10.1109/TVCG.2019.2934619.
Wickham, Hadley, Dianne Cook, Heike Hofmann, and Andreas Buja. 2011. “Tourr: An R Package for Exploring Multivariate Data with Projections.” Journal of Statistical Software 40 (2): 1–18. https://doi.org/10.18637/jss.v040.i02.