domain: info math

text:
Gabriel Laberge
email: gabriel.laberge@polymtl.ca

Yann Pequignot
email: yann.pequignot@iid.ulaval.ca

Understanding Interventional TreeSHAP Understanding Interventional TreeSHAP : How and Why it Works

Keywords: TreeSHAP, Decision Trees, Shapley Values, Attributions, Explainability

Shapley values are ubiquitous in interpretable Machine Learning due to their strong theoretical background and efficient implementation in the SHAP library. Computing these values previously induced an exponential cost with respect to the number of input features of an opaque model. Now, with efficient implementations such as Interventional TreeSHAP, this exponential burden is alleviated assuming one is explaining ensembles of decision trees. Although Interventional TreeSHAP has risen in popularity, it still lacks a formal proof of how/why it works. We provide such proof with the aim of not only increasing the transparency of the algorithm but also to encourage further development of these ideas. Notably, our proof for Interventional TreeSHAP is easily adapted to Shapley-Taylor indices and one-hot-encoded features.

Introduction

Ever since their introduction, Random Forests [START_REF] Breiman | Random forests[END_REF] and Gradient-Boosted-Trees (Friedman, 2001) have retained state-of-the-art performance for Machine Learning (ML) tasks on structured data [START_REF] Grinsztajn | Why do tree-based models still outperform deep learning on tabular data?[END_REF]. Still, by aggregating ensembles of decision trees rather than considering a single one, both models do away with the inherent transparency of decision trees in favor of more opaque decision-making mechanisms. Despite having high performance, the black box nature of these models is a considerable hurdle to their widespread applications as humans are not inclined to use tools that they cannot understand/explain [START_REF] Barredo Arrieta | Explainable artificial intelligence (xai): Concepts, taxonomies, opportunities and challenges toward responsible ai[END_REF].

To this end, research on the subject of explaining opaque models has been flourishing in the past few years. Notably, a method called SHAP (Lundberg and Lee, 2017) has recently been invented to provide explanations of any model decisions in the form of feature attributions, where a score (positive/negative or null) is assigned to each input feature and is meant to convey how much said feature was used in a specific model decision. These scores are based on the well-known Shapley values from coalitional game theory [START_REF] Lloyd | A value for n-person games[END_REF]. However, computing these Shapley values for arbitrary models induces an exponential cost in terms of the number of input features, which inhibits their application to most ML tasks.

The exponential burden of Shapley values has lately been alleviated for tree ensemble models (e.g. Random Forests and Gradient-Boosted-Trees) via two efficient algorithms called Interventional TreeSHAP and Conditional TreeSHAP (Lundberg et al., 2020). The two algorithms differ in how their game theory formulation handles inputs with missing features. The invention of these algorithms has played a major role in making the SHAP Python library the most popular framework for shedding light on model decisions [START_REF] Holzinger | Explainable ai methods-a brief overview[END_REF]. Yet, the original paper is limited to the presentation of the algorithms, without a mathematical proof to justify their correctness. Some effort has subsequently been made to explain the main intuitions on how Interventional TreeSHAP works, as witnessed for example in the blog of [START_REF] Chen | Understanding shapley value explanation algorithms for trees[END_REF] which contains nice interactive visualizations. Still, to the best of the author's knowledge, a detailed proof that Interventional TreeSHAP works has not yet been written. This is the purpose of this paper and we believe it is important for multiple reasons.

• Educational: A correctness proof for an algorithm can be used as content for a math-focused class on interpretable ML.

• Transparency: It brings to light the assumptions made by the algorithm and the theoretical quantities it is computing. It alleviates the possibility of practitioners treating TreeSHAP as "a black box to explain a black box".

• Transferability: The proof for an algorithm allows one to derive proofs for similar algorithms.

The main objective of this paper is to provide the first complete proof of how/why Tree-SHAP works. We will focus on the "Interventional" setting of TreeSHAP, where features are perturbed without consideration to the joint data distribution. The reason is that this algorithm is used by default any time practitioners provide a reference dataset to TreeSHAP 1 . Our contributions are the following:

1. We provide the first detailed proof of how/why Interventional TreeSHAP works.

2. The proof is shown to be effortlessly transferable to other Game Theory indices like the Shapley-Taylor indices (Sundararajan et al., 2020). Moreover, the proof is extended to features that are one-hot encoded, something that is not currently supported in the SHAP library.

3. We provide C++ implementations for Taylor-TreeSHAP, and Partition-TreeSHAP wrapped in Python 2 . Crucially, this C++ implementation uses the same notation as in the paper to serve as complementary resources for the interested reader.

The rest of the paper is structured as follows. We begin by introducing Shapley values in Section 2, and Decision Trees in Section 3. Then, Section 4 presents our proof of correctness for the TreeSHAP algorithm. Next, our theoretical results are leveraged to effortlessly generalize TreeSHAP to the Shapley-Taylor index in Section 5, and to one-hot encoded features in Section 6. Finally, Section 7 concludes the paper.

Feature Attribution via Shapley Values

Shapley Values

Coalitional Game Theory studies situations where d players collaborate toward a common outcome. Formally, letting [d] := {0, 1, . . . , d -1} be the set of all d players, this theory is concerned with games ν : 2 [d] → R, where 2 [d] is the set of all subsets of [d], which describes the collective payoff that any set of players can gain by forming a coalition. In this context, the challenge is to assign a credit (score) φ i (ν) ∈ R to each player i ∈ [d] based on their contribution toward the total value ν([d])ν(∅) (the collective gain when all players join, taking away the gain when no one joins). Namely, such scores should satisfy:

d i=1 φ i (ν) = ν([d]) -ν(∅).
(1)

The intuition behind this Equation is to think of the outcomes ν([d]) and ν(∅) as the profit of a company involving all employees and no employee. In that case, the score φ i (ν) can be seen as the salary of employee i based on their productivity. There exist infinitely many score functions that respect Equation 1, hence it is necessary to define other desirable properties that a score function should possess: Dummy, Symmetry, and Linearity.

Dummy In cooperative games, a player i is called a dummy if ∀S ⊆ [d] \ {i} ν(S ∪ {i}) = ν(S).
Dummy players basically never contribute to the game. A desirable property of a score is that dummy players should not be given any credit, i.e. employees that do not work do not make a salary,

∀S ⊆ [d] \ {i} ν(S ∪ {i}) = ν(S) ⇒ φ i (ν) = 0. ( 2
)
Symmetry Another property is symmetry which states that players with equivalent roles in the game should have the same score i.e. employees with the same productivity should have the same salary

∀S ⊆ [d] \ {i, j} ν(S ∪ {i}) = ν(S ∪ {j}) ⇒ φ i (ν) = φ j (ν). ( 3
)
Linearity The last desirable property is that scores are linear w.r.t games, i.e. if we let φ(ν) := [φ 1 (ν), φ 2 (ν), . . . , φ d (ν)] T , then for all games ν, µ : 2 [d] → R and all α ∈ R, we want

φ(ν + µ) = φ(ν) + φ(µ). (4) φ(αµ) = αφ(µ). (5)
The reasoning behind this property is a bit more involved than the previous two. For Equation 4, imagine that the two games ν and µ represent two different companies and that employee i works at both. In that case, the salary of employee i from company ν should not be affected by their performance in the company µ and vice-versa. Importantly, the total salary of employee i ideally should be the sum of the salaries at both companies.

For Equation 5, we imagine that the company is subject to a law-suit in the end of a quarter which results in a sudden reduction in profits by a factor of α. Then, given that each employee had fixed productivity during this quarter, it is only fair that all their salaries should also diminish by the same factor α.

In his seminal work, Lloyd Shapley has proven the existence of a unique score function that respects Equations 1-5: the so-called Shapley values.

Definition 1 (Shapley values [START_REF] Lloyd | A value for n-person games[END_REF]) Given a set [d] := {1, 2, . . . , d} of players and a cooperative game ν : 2 [d] → R, the Shapley values are defined as

φ i (ν) = S⊆[d]\{i} W (|S|, d) ν(S ∪ {i}) -ν(S) i ∈ [d], (6)
where

W (k, d) := k!(d -k -1)! d! (7)
is the proportion of all d! orderings of [d] where a given subset S of size k appears first, directly followed by a distinguished element i / ∈ S.

Intuitively, the credit φ i (ν) is attributed to each player i ∈ [d] based on the average contribution of adding them to coalitions S that excludes them. Notice that the number of terms in Definition 1 is exponential in the number of players.

We record here a simple property of Shapley values with respect to dummy players that will be essential in our derivations.

Lemma 2 (Dummy Reduction) Let D ⊆ [d] be the set of all dummies, and D C = [d]\D be the set of non-dummy players, then

φ i (ν) = 0 if i ∈ D S⊆D C \{i} W (|S|, |D C |) ν(S ∪ {i}) -ν(S) otherwise. ( 8
)
Simply put, dummy players are given no credit, and the credit of all remaining players follows the basic Shapley definition while assuming that the set of players is

D C instead of [d].
Proof Let j be a dummy but not i, we have

φ i (ν) = S⊆[d]\{i,j} W (|S|, d) ν(S ∪ {i}) -ν(S) + W (|S| + 1, d) ν(S ∪ {i, j}) -ν(S ∪ {j}) = S⊆[d]\{i,j} W (|S|, d) + W (|S| + 1, d) ν(S ∪ {i}) -ν(S) = S⊆[d]\{i,j} W (|S|, d -1) ν(S ∪ {i}) -ν(S) .
Repeat this process for all dummies.

This property is key as it implies that Shapley values of non-dummy players are unaffected by the inclusion of an arbitrarily large number of new dummy players. It also means that, once all dummy players are identified, they can be ignored and the Shapley value computations will only involve the set D C non-dummy players.

Feature Attribution as a Game

For a long time, the focus of Machine Learning (ML) has been on improving generalization performance, regardless of the cost of model interpretability. For instance, because of their state-of-the-art performance, tree ensembles are typically used instead of individual decision trees which are inherently more interpretable. However, the ML community has reached a point where the lack of transparency of the best-performing models inhibits their widespread acceptance and deployment [START_REF] Barredo Arrieta | Explainable artificial intelligence (xai): Concepts, taxonomies, opportunities and challenges toward responsible ai[END_REF]. To address this important challenge, the research community has been working for the past few years on techniques that shed light on the decision-making of opaque models. A popular subset of such techniques provide insight on model decisions in the form of feature attribution i.e. given an opaque model h and an input x ∈ R d , a score φ i (h, x) ∈ R is provided to each feature i ∈ [d] in order to convey how much feature i was used in the decision h(x). Given the lack of ground truth for the feature attribution for an opaque model, the community has focused on exploiting the existence and uniqueness of Shapley values to the problem of explaining ML models [START_REF] Sundararajan | The many shapley values for model explanation[END_REF]. Following the BaselineShap formulation of [START_REF] Sundararajan | The many shapley values for model explanation[END_REF], when explaining the model prediction h(x) at some input x of interest, we can compare said prediction to the prediction h(z) at a baseline value of the input z. In this context, feature attributions can be formulated as feature contributions towards the gap h(x)h(z) viewed as the total value of a carefully designed coalitional game. Defining such a game requires specifying the collective payoff for every subset of features. In BaselineShap, this is achieved by defining the collective payoff for a given set S of features to be the prediction of the model at the input whose value for features from S are given by the point of interest x, while other feature values are taken from the baseline point z. Formally, given an input of interest x, a subset of features S ⊆ [d] that are considered active, and the baseline z, the replace function r z S : R d → R d , defined as

r z S (x) i = x i if i ∈ S z i otherwise, (9)
is used to simulate the action of activating features in S (or equivalently shutting down features not in S). The resulting coalitional game for ML interpretability is the following.

Definition 3 (The Baseline Interventional Game) Comparing the model predictions at x and z can be done by computing the Shapley values of the following game:

ν h,x,z (S) := h( r z S (x) ). ( 10
)
This formulation is called Interventional because we intervene on feature i by replacing its baseline value z i with the value x i irrespective of the value of other features. Hence we break correlations between the various features.

By Equation 1, the resulting Shapley values φ(ν h,x,z ) ≡ φ(h, x, z) will sum to the gap

d i=1 φ i (h, x, z) = h(x) -h(z). (11)
(1, 1) (-1, 1)

(1, -1) (-1, -1) Therefore, Shapley values following this Interventional game formulation are advertised as a mean to answer contrastive questions such as : Why does my model attribute a higher risk of stroke to person A compared to person B?

φ 0 += f (1, -1) -f (-1, -1) φ 0 += f (1, 1) -f (-1, 1) φ 1 += f (-1, 1) -f (-1, -1) φ 1 += f (1, 1) -f (1, -1)
We finish this Section with a toy example that illustrates how Interventional Shapley values are computed. We shall be explaining a two-dimensional AND function

h(x) = ½(x 0 > 0)½(x 1 > 0). ( 12
)
Our goal is to explain the discrepancy between h(x) = 1 with x = (1, 1) T and h(z) = 0 with z = (-1, -1) T . Let us begin by computing φ 0 (h, x, z) by directly plugging in the definition

φ 0 (h, x, z) = S⊆{1} |S|!(d -|S| -1)! d! h( r z S∪{0} (x) ) -h( r z S (x) ) = 1 2 h( r z {0,1} (x) ) -h( r z {1} (x) ) + 1 2 h( r z {0} (x) ) -h( r z ∅ (x) ) = 1 2 h(1, 1) -h(-1, 1) + 1 2 h(1, -1) -h(-1, -1) = 1 2 × 1 + 1 2 × 0 = 1 2 . ( 13
)
Same thing for φ 1 (h, x, z). We see that φ 0 (h, x, z) = φ 2 (h, x, z), which is aligned with the symmetry property (cf. Equation 3), and that φ 0 (h, x, z) + φ 1 (h, x, z) = 1 = h(x)h(z). Figure 1 shows the intuition behind this computation. We see there are two coordinate-parallel paths that go from z to x. We average the contribution of changing the ith component across these two paths.

Tree-Based Models

Decision Tree

A directed graph G = (N, E) is a set of nodes n ∈ N and edges e ∈ E ⊂ N × N . The node at the tail of e is e 0 ∈ N while the node at the head of the edge is e 1 ∈ N . The node e 1 is called a child of e 0 . A full binary tree is a rooted tree in which every node has exactly two children (a left one and a right one) or none. We view such a graph as a directed graph by making all its edges point away from the root. We denote a full binary tree by T = (N, E) where N = {0, 1, . . . , |N | -1} is the set of nodes and E ⊂ N × N is the set of directed edges and write 0 ∈ N for the root. An internal node is a node n which has two children l < r and l is called the left child of n and r is called the right child of n. In this case, we say that (n, r) is a right edge and (n, l) is a left edge. A leaf is a node with no children and all leaves are stored in the set L ⊆ N .

Definition 4 (Binary Decision Tree) A Binary Decision Tree on R d is full binary tree T = (N, E) in which every internal node n is labeled by a pair

(i n , γ n ) ∈ [d] × R and every leaf l ∈ L is labeled with a value v l . For an internal node n, the label (i n , γ n ) encodes the boolean function R n : R d → {0, 1} given by R n (x) := ½(x in ≤ γ n ).
See Figure 2 for a simple example of Binary Decision Tree. Any Binary Decision Tree induces a function h : R d → R defined as follows. For every x ∈ R d , we start at the top of the tree (the root) and check the condition R 0 (x) := ½(x i 0 ≤ γ 0 ): if it is true we go down to the left child of the root, and if it is false we go down to the right child. This procedure is repeated until we reach a leaf node l and the model outputs h(x) = v l . For instance, in Figure 2, we see that for the input x = (3.4, 0.2, 2) T , we go from the root to the node 1 and end up at the leaf 4, so h(x) = v 4 . We note that the input "flowed through" the sequence of edges ( (0, 1), (1, 4) ) which goes from root to leaf. We shall refer to such a sequence as a maximal path.

Definition 5 (Maximal Path) A directed path P in a full binary tree

T = (N, E) is sequence P = (e [k] ) ℓ-1 k=0 of edges in E such that the e [k] 1 = e [k+1] 0
for all k = 0, 1, . . . , ℓ -2. A maximal path is a directed path P = (e [k] ) ℓ-1 k=0 that cannot be extended (and if it has a positive length then it starts at the root and ends at a leaf ).

Examples of maximal paths in this decision tree of Figure 2 include P = ( (0, 1), (1, 4) ) and P = ( (0, 2), (2, 5) ). Given the definition of maximal path, we now aim at describing the model h in a more formal manner. Since our intuition about h is that x flows downward on edges selected by the Boolean functions, our notation should only involve edges. Hence, for an edge e = (e 0 , e 1 ), we define i e as the feature index of the internal node e 0 at its tail. In Figure 2, we have that i (1,4) = 2 for example. Also, for each edge e = (e 0 , e 1 ) we define the Boolean function R e (x) by R e 0 (x) if e is a left edge and 1 -R e 0 (x) otherwise. When R e (x) = 1 for some edge e, we shall say that x "flows though" the edge e, a terminology that will be used throughout this paper. Now, for each maximal path P ending at some leaf l ∈ L we define h P : R d → R by

h P (x) = v l e∈P R e (x). (14) 0 1 2 3 4 5 6 i 0 = 1 γ 0 = 0.5
x 1 ≤ 0.5?

i 1 = 2 γ 1 = 1.33
x 2 ≤ 1.33?

i 2 = 0 γ 2 = 0.25
x 0 ≤ 0.25?

v 3 v 4 v 5 v 6
Yes No This step function outputs zero unless the input flows through all the edges in the maximal path P . For example, in Figure 2, the function h P associated with P = ( (0, 1), (1, 4) )

is h P (x) = v 4 ½(x 1 ≤ 0.5)½(x 2 > 1.33).
Finally, given an input x, there exists only one maximal path P such that h P (x) = 0. This is because any given x can only flow through one path P from root to leaf. Hence, we can interpret h as

h(x) = P h P (x), (15)
where the sum is taken over all maximal paths in the Decision Tree. Note that the decision tree function h of Figure 2 can be written as

h(x) = v 3 ½(x 1 ≤ 0.5)½(x 2 ≤ 1.33) + v 4 ½(x 1 ≤ 0.5)½(x 2 > 1.33) +v 5 ½(x 1 > 0.5)½(x 0 ≤ 0.25) + v 6 ½(x 1 > 0.5)½(x 0 > 0.25).

Interventional Tree SHAP

As previously highlighted, computing Shapley values (cf. Definition 1) requires summing over an exponential number of subsets S ⊆ [d] \ {i}. This exponential complexity previously prohibited the application of Shapley values to ML tasks which typically involve a large number of features. Nonetheless, by exploiting the structure of Decision Trees, Interventional TreeSHAP alleviates this exponential complexity in d at the cost of no longer being model-agnostic. We now describe step-by-step how and why TreeSHAP works.

In this section, we shall assume x and z are fixed and we are concerned with computing Shapley values for a forest F of decision trees, namely φ(F, x, z). A first application of linearity (cf. Equations 4 & 5) shows that

φ(F, x, z) = φ 1 |F| h∈F h, x, z (16)
= 1 |F| h∈F φ(h, x, z), (17)
Henceforth, we can thus fix a decision tree h and focus on how to compute φ(h, x, z).

Naive Tree Traversal

Since the function represented by the decision tree h can be written as a sum over all maximal paths (cf. Equation 15), a second application of linearity (cf. Equation 4) allows us to derive

φ(h, x, z) = φ P h P , x, z = P φ(h P , x, z), (18)
Shapley values for a decision tree are therefore equal to the sum of Shapley values over all maximal paths in the tree. This means that the feature attributions can be computed via the following tree-traversal algorithm.

Algorithm 1 Tree SHAP Naive Pseudo-code

1: procedure Recurse(n) 2: if n ∈ L then 3: φ += φ(h P , x, z)
⊲ Add contribution of the maximal path

Compute the Shapley Value of a Maximal Path

We can now fix a maximal path P in the decision tree h and focus on the Shapley values φ(h P , x, z). We first identify four types of edges X, Z, F , B which can occur in P .

Definition 6 (Edge Type) We say that an edge e ∈ E is of

Type X if R e (x) = 1 and R e (z) = 0 Type Z if R e (x) = 0 and R e (z) = 1 Type F if R e (x) = 1 and R e (z) = 1 Type B if R e (x) = 0 and R e (z) = 0. ( 19
)
Here X stands for x flows, Z stands for z flows, F stands for both Flow, and B stands for both are Blocked.

See Figure 3 for an informal example of each of these types of edges for a fixed maximal path P . Moreover, Figure 4 presents the previous example of a simple decision tree where each edge is colored with respect to its type. From this point on in the document, we will systematically color edges w.r.t their type.

Lemma 7 If P contains an edge of type B, then

∀ S ⊆ [d] h P ( r z S (x) ) = 0.
Proof Let e be an edge of type B in P . Then for every S ⊆ [d], we have R e (r z S (x)) = 0, which implies that h P (r z S (x)) ∝ R e (r z S (x)) = 0.

Corollary 8 If P contains an edge of B , then φ(h P , x, z) = 0.

Proof It follows from Lemma 7 and the linearity property of Shapley values (cf. Equation 5with α = 0). Indeed, by definition, linear functions map zero to zero so the Shapley values of the null game are null. 0 1 2 3 4 5 6

i 0 = 1 γ 0 = 0.5 i 1 = 2 γ 1 = 1.33 i 2 = 0 γ 2 = 0.25 v 3 v 4 v 5 v 6
i 0 = 1 γ 0 = -0.5
x 1 > -0.5?

i 1 = 2 γ 1 = 1.5
x 2 > 1.5?

i 2 = 1 γ 2 = 1 x 1 ≤ 1? i 3 = 0 γ 3 = -1 x 0 > -1? i 4 = 1 γ 4 = -0.33
x 1 > -0.33?

i 5 = 0 γ 5 = -1.5
x 0 ≤ -1.5? Now, assuming P does not contain any type B edges, we have (20)

h P (r z S (x)) = v l e∈P R e (r z S (x)) = v l e∈P e type X R e (r z S (x)) e∈P e type Z R e (r z S (x)) e∈P e type F R e (r z S (x)) =1 ∀ S = v l e∈P e type X ½(i e ∈ S)
For an edge e, recall that i e denotes the feature index at its tail e 0 . The last line follows from the observation that, for an edge e of type X , the only times R e (r z S (x)) = 1 are when the i e th component of r z S (x) is set to x and not z (i.e. i e ∈ S). Alternatively, for an edge e of type Z , R e (r z S (x)) = 1 if and only if the i e th component of r z S (x) is set to z and not x (i.e. i e / ∈ S).

We define the three following sets S X : = {i e : e ∈ P, and e is of type X}, S Z : = {i e : e ∈ P, and e is of type Z}.

S XZ := S X ∪ S Z .

(21)

See Figure 5 for an example of sets S X and S Z on some maximal path. It is important to realize that the sets S X , S Z , and S XZ depend on the current maximal path P . Still, we assume that P is fixed and hence we do not make the dependence explicit in the notation.

Lemma 9 If S X ∩ S Z = ∅, then ∀ S ⊆ [d] h P ( r z S (x) ) = 0. ( 22
)
Proof Let j be a feature common to both S X and S Z . Then, there must exists an edge e of X and an edge e ′ of type Z such that j = i e = i e ′ . From Equation 20, we have

h P ( r z S (x) ) ∝ ½(j ∈ S)½(j / ∈ S) = 0. Corollary 10 If S X ∩ S Z = ∅, then φ(h P , x, z) = 0.
Proof By Lemma 9 and Linearity of the Shapley values (cf. Equation 5).

We observe that Corollary 8 & 10 provide sufficient conditions for the contributions at line 3 of Algorithm 1 to be null. We now provide a result that highlights which features are dummies of the Coalitional Game for the maximal path P .

Lemma 11 If a feature does not belong to S XZ , then it is a dummy feature for the Baseline Interventional Game ν h P ,x,z (cf. Definition 3).

Proof If we assume there exists a type B edge in P , then by Lemma 7, the game is null and all players are dummies. In the non-trivial case where P does not contain a type B edge, we must let i / ∈ S XZ be an index, and S ⊆ [d] \ {i} be an arbitrary subset of players that excludes i, and show that h P ( r z S∪{i} (x) ) = h P ( r z S (x) ). Since i / ∈ S XZ , there are no edges e of type X or Z such that i e = i. Moreover, since i = i e implies the equivalence i e ∈ S ⇐⇒ i e ∈ S ∪ {i}, we have

h P (r z S (x)) = v l e∈P e type X ½(i e ∈ S) e∈P e type Z ½(i e / ∈ S) = v l e∈P e type X ½(i e ∈ S ∪ {i}) e∈P e type Z ½(i e / ∈ S ∪ {i}) = h P (r z S∪{i} (x)),
which concludes the proof.

By Lemma 2, we note that computing the Shapley values φ(h P , x, z) will only require evaluating the game ν h,x,z (S) := h P ( r z S (x) ) for coalitions S ⊆ S XZ . Additionally, we will assume w.l.o.g that the current maximal path contains no type B edges and that S X and S Z are disjoint. Indeed, failing to reach these requirements will simply cause the Shapley values to be zero.

Lemma 12 (Flow Blocking) If P contains no type B edges and the sets S X and S Z are disjoint, then for any S ⊆ S XZ we have

h P ( r z S (x) ) = v l if S = S X 0 otherwise, (23)
where l ∈ L is the leaf node at the end of P .

Proof Since P does not contain a type B edge, we can use Equation 20, which, as a reminder, states that

h P (r z S (x)) = v l e∈P e type X ½(i e ∈ S) e∈P e type Z ½(i e / ∈ S). (24)
We need to prove the following two statements.

1. h P (r z S X (x)) = v l . On the one hand, for every edge e of type X in P , by definition i e ∈ S X . On the other hand, for every edge e of type Z in P , by definition i e ∈ S Z , so i e / ∈ S X since we assume that S X ∩ S Z = ∅. Therefore it follows that h P (r z S X (x)) = v l using Equation 24.

2. If S ⊆ S XZ and S = S X , then h P (r z S (x)) = 0. Assume that S ⊆ S XZ and S = S X . Since, S = S X , at least of the two following cases must occur, (a) there exists j ∈ S X \S or (b) there exists j ∈ S \ S X .

(a) Let j ∈ S X \ S. We can find e ∈ P of type X such that i e = j. We then have ½(i e ∈ S) = 0.

(b) Let j ∈ S \ S X . Since S ⊆ S XZ , it follows that j ∈ S Z . We can find e ∈ P of type Z such that i e = j. Then as j ∈ S, we have ½(i e / ∈ S) = 0.

Given that either case (a) or case (b) must occur, using Equation 24 we see that h P (r z S (x)) = 0, as desired.

We now arrive at the main Theorem which highlights how Interventional TreeSHAP computes Shapley values while avoiding the exponential cost w.r.t the number of input features. This Theorem is the culmination of all previous results : Lemma 2, Corollary 8 & 10 and Lemma 11 & 12.

Theorem 13 (Complexity Reduction) If P contains no type B edges and the sets S X and S Z are disjoint, then all features that are not in S XZ are dummies and we get

φ i (h P , x, z) = S⊆S XZ \{i} W (|S|, |S XZ |) h P ( r z S∪{i} (x) ) -h P ( r z S (x) ) i ∈ S XZ . (25)
The exponential cost O(2 |S XZ | ) of computing these terms reduces to O(1)

following i / ∈ S XZ ⇒ φ i (h P , x, z) = 0 (26) i ∈ S X ⇒ φ i (h P , x, z) = W (|S X | -1, |S XZ |)v l (27) i ∈ S Z ⇒ φ i (h P , x, z) = -W (|S X |, |S XZ |)v l , (28)
given that the coefficients W where computed and stored in advance.

Proof Given Lemma 11, we know that all features not in S XZ are dummies. Hence applying Lemma 2 yields Equation 25 and 26. We now prove 27 and 28 separately. Suppose i ∈ S X , then according to Lemma 12 the only coalition S ⊆ S XZ \{i} for which h P ( r z S∪{i} (x) )h P ( r z S (x) ) is non-null is when S = S X \ {i}. Indeed, when S = S X \ {i}

h P ( r z S∪{i} (x) ) -h P ( r z S (x) ) = h P ( r z S X (x) ) -h P ( r z S X \{i} (x) ) = v l -0 = v l . So, we get a Shapley value W (|S|, |S XZ |)v l = W (|S X \{i}|, |S XZ |)v l = W (|S X |-1, |S XZ |)v l .
Now suppose i ∈ S Z , according to Lemma 12 the only coalition S ⊆ S XZ \ {i} for which h P ( r z S∪{i} (x) )h P ( r z S (x) ) is non-null is when S = S X Indeed, when S = S X h P ( r z S∪{i} (x) )

-h P ( r z S (x) ) = h P ( r z S X ∪{i} (x) ) -h P ( r z S X (x) ) = 0 -v l = -v l .
We therefore get a Shapley value W (|S|,

|S XZ |)v l = -W (|S X |, |S XZ |)v l .
The complexity reduction Theorem is the main reason Interventional TreeSHAP works so efficiently. Indeed, the exponential complexity of Shapley values w.r.t the number of input features used to severely limit their application to high-dimensional machine learning tasks. Interventional TreeSHAP gets rid of this exponential complexity by noticing that decision stumps h P are AND functions. This drastically reduces the number of coalitions S ⊆ S XZ \ {i} to which adding player i changes the output of the model.

Efficient Tree Traversal

In this section, we leverage theoretical results from the previous section to improve the dynamic tree traversal in Algorithm 1. First, by virtue of Theorem 13, given the path P between the root and the current node in the traversal, we only need to keep track of the sets S X and S Z . Indeed once we reach a leaf (and P becomes a maximal path), we will only need these two sets of features to compute the Shapley values. Figure 6

Now that we know the two data structures to track during the tree traversal, we are left with optimizing the tree traversal itself. Corollary 8 & 10 give us sufficient conditions for when the contributions of line 3 of Algorithm 1 are null. Hence, we must design the tree traversal in a way that avoids reaching maximal paths P whose contributions are guaranteed to be zero.

Firstly, from Corollary 8, we should avoid going down type B edges during the traversal. This is because any maximal path P that follows this edge will contain a type B edge and hence have null Shapley values. Therefore, if during the tree traversal we encounter a split where both x and z flow through the same edge, we only need to follow that edge of type F and the sets S X and S Z remain unchanged, see Figure 6(a). We call this the Scenario 1.

Secondly, Corollary 10 informs us that, as we traverse the tree, we must only follow paths where the sets S X and S Z are disjoint. If we follow paths where the sets are not disjoint, then any maximal path we reach will have zero Shapley values resulting in wasted computations. Therefore, if a node n is encountered such that x and z go different ways, and the associated feature i n is already in S XZ , then 1. if i n ∈ S X , go down the same direction as x 2. if i n ∈ S Z , go down the same direction as z. This is necessary to keep the sets S X and S Z disjoint. These two cases are illustrated in Figure 6(b) and (c) and are referred to as Scenario 2.

The final scenario that can occur when reaching a node is when x and z do not go the same way and the feature i n is not already in S XZ . In that case. we must visit both branches and update the sets S X , S Z accordingly, see Figure 7. We refer to this as the Scenario 3.

We have now identified every scenario that can occur during the tree traversal, as well as the two data structures S X , S Z that we must store during the exploration. Algorithm 2 presents the final pseudo-code for Interventional TreeSHAP based on Theorem 13 and our insights on how to efficiently traverse the tree. The complexity of this algorithm depends n The intuition is that we can avoid the for-loop at line 3 by propagating the contributions at lines 5 and 7 up in the tree. However, we have found that this additional optimization does not generalize to other game theory indices, such as the Shapley-Taylor index presented in the coming section. Hence, we prefer to see Algorithm 2 as the most general/versatile formulation of Interventional TreeSHAP.

... ... ... (S X , S Z ) (S X , S Z ∪ {i n }) (S X ∪ {i n }, S Z ) i n / ∈ S X i n / ∈ S Z
Algorithm 2 Interventional Tree SHAP

1: procedure Recurse(n, S X , S Z ) 2: if n ∈ L then 3: for i ∈ S X ∪ S Z do ⊲ cf. Theorem 13 4: if i ∈ S X then 5: φ i += W (|S X | -1, |S XZ |)v n ; 6:
else 7:

φ i -= W (|S X |, |S XZ |)v n ; 8: end if 9:
end for 10:

else if x child = z child then ⊲ Scenario 1 11:
return Recurse(x child , S X , S Z );

12:

else if i n ∈ S X ∪ S Z then ⊲ Scenario 2 13: if i n ∈ S X
Recurse(x child , S X ∪ {i n }, S Z ); 20: Recurse(z child , S X , S Z ∪ {i n }); 21:
end if 22: end procedure 23: φ = 0; 24: Recurse(0, S X = ∅, S Z = ∅); 25: return φ;

Shapley-Taylor Indices

One of the purposes of deriving a proof for Interventional TreeSHAP is that it can be leveraged to discover efficient algorithms for computing other Game Theory indices. In this section, we employ previous results to prove how to compute Shapley-Taylor Indices efficiently.

Game Theory

Definition 14 (Shapley Taylor Indices (Sundararajan et al., 2020)) Given a set of d players [d] := {1, 2, . . . , d} and a cooperative game ν : 2 [d] → R, the Shapley-Taylor Indices are defined as

Φ ij (ν) =      ν({i}) -ν(∅) if i = j (Main Effect) S⊆[d]\{i,j} W (|S|, d)∇ ij (S) otherwise (Interactions). ( 29
) with ∇ ij (S) = ν(S ∪ {i, j}) -ν(S ∪ {j}) -ν(S ∪ {i}) -ν(S) . (30)
The Shapley-Taylor Indices were invented as a way to provide interaction indices that respect the same additive property as the original Shapley values

d i=1 d j=1 Φ ij (ν) = ν([d]) -ν(∅). (31)
As with classical Shapley values, the Shapley-Taylor indices assign no credit to dummy players. Letting D be the set of dummy players, we have

i ∈ D or j ∈ D ⇒ Φ ij (ν) = 0. ( 32
Φ ij (ν) =      0 if i ∈ D or j ∈ D ν({i}) -ν(∅) else if i = j S⊆D C \{i,j} W (|S|, |D C |)∇ ij (S) otherwise. (33)
Proof The proof is mutatis mutandis like the proof of Lemma 2.

We consider in the sequel the Shapley-Taylor indices associated with the Baseline Interventional game ν h,x,z (cf. Definition 3) for a model h, an instance x and a baseline instance z. We simply write Φ(h, x, z) in place of Φ(ν h,x,z ) for these indices.

Shapley-Taylor Indices Computation

Since the Shapley-Taylor Indices are also linear w.r.t coalitional games, computing these indices for a forest of decision trees reduces to the computation of these indices for a decision stump h P associated with a maximal path P . Just like with Shapley values, we can use Algorithm 1 as the skeleton of our algorithm. Fixing a decision tree h, instances x and z, as well as a maximal path P in h, we focus on the computation of the Shapley-Taylor Indices Φ(h P , x, z).

First we note that Lemma 7 & 9 lead to similar corollaries about Shapley-Taylor Indices.

Corollary 16 If P contains an edge of type B , then Φ(h P , x, z) = 0.

Proof Follows from Lemma 7 and the linearity of Shapley-Taylor indices.

Corollary 17 If S X ∩ S Z = ∅, then Φ(h P , x, z) = 0.
Proof By Lemma 9 and Linearity of the Shapley-Taylor values.

Once we reach a leaf we are meant to compute the Shapley-Taylor Indices of the decision stump h P associated with the current maximal path P . We again use Lemma 12 to reduce the complexity.

Theorem 18 (Complexity Reduction for Shapley-Taylor) If P contains no type B edges and the sets S X and S Z are disjoint, then all features that are not in S XZ are dummies and we get

Φ ii (h P , x, z) = h P (r z {i} (x)) -h P (r z ∅ (x)) i ∈ S XZ , (34)
Φ ij (h P , x, z) = S⊆S XZ \{i,j} W (|S|, |S XZ |)∇ ij (S) i, j ∈ S XZ , i = j (35)
with

∇ ij (S) := h P ( r z S∪{i,j} (x) ) -h P ( r z S∪{j} (x) ) -h P ( r z S∪{i} (x) ) -h P ( r z S (x) ) (36)
The exponential cost O(2

|S XZ | ) of computing Φ ij reduces to O(1) following S X = {i} ⇒ Φ ii (h P , x, z) = v l (37) i ∈ S Z and S X = ∅ ⇒ Φ ii (h P , x, z) = -v l (38) i = j and i, j ∈ S X ⇒ Φ ij (h P , x, z) = W (|S X | -2, |S XZ |)v l (39) i = j and i, j ∈ S Z ⇒ Φ ij (h P , x, z) = W (|S X |, |S XZ |)v l (40) i = j and i ∈ S X , j ∈ S Z ⇒ Φ ij (h P , x, z) = -W (|S X | -1, |S XZ |)v l (41) else Φ ij (h P , x, z) = 0, ( 42
)
given that the coefficients W are computed and stored in advance.

Extension to Partitions of Features

In certain settings, one may be interested in characterizing the effect of a set of features on the model's output, instead of considering their individual effects. This can be achieved by treating a set of features as a single super-feature. ] to its group index I(j). Note that the pre-image map I -1 : 2 [d] → 2 [d ′ ] allows to recover the groups of features using the partition notation:

I -1 ({i}) = P i , i ∈ [d].
The partition of the d ′ features into d groups naturally induces a way to associate to any game ν on [d ′ ] a game ν I on [d] given by ν I (S) = ν(I -1 (S)) for all S ⊆ [d]. In our specific case, given inputs x and z for a model h, we have

ν I h,x,z (S) := ν h,x,z (I -1 (S)) = h( r z I -1 (S) (x) ). (43)
See Figure 8 for an illustration of how the replace function r z I -1 (S) (x) is employed in ν I . We note that features within the same group are always replaced simultaneously and so Shapley values for the game ν I h,x,z represent the joint contributions of each group towards the gap h(x)h(z). Computing Shapley values for the game ν I h,x,z for a decision Tree h cannot be done using TreeSHAP, but we now show how to leverage our previous results to adapt TreeSHAP in this new setting.

Firstly, by linearity of the Shapley values we can again focus on a single maximal path P , and study the Shapley values of the game ν I h P ,x,z . Henceforth, we freely use the concepts and notations introduced in the previous sections for the computation of the Shapley values for the game ν h P ,x,z on [d ′ ] and we show how to use them to analyze the game ν I h P ,x,z . For example, type X , type Z edges and the sets S X , S Z are all defined as in Section 4 with respect to the maximal path h P in a decision tree h and the inputs x and z. We note that if P contains a type B edge, then Lemma 7 ensures that the game ν h P ,x,z is null and this implies that the game ν I h P ,x,z is null too. The resulting Shapley values φ(ν I h P ,x,z ) are therefore constantly zero. Hence, we can again ignore maximal paths with type B edges. The next result is analogous to Lemma 9 but for the game ν I .

Lemma 19 If I(S X ) ∩ I(S Z ) = ∅, then ∀ S ⊆ [d] ν I h P ,x,z (S) = 0. ( 44
)
Proof Since I(S X ) ∩ I(S Z ) = ∅, we can find an index j ∈ [d] that belongs to both I(S X ) and I(S Z ). By definition of S X and S Z , this means that we can find in P an edge e of z z 0 z 1 z 2 z 3 z 4 z 5 z 6 z 7

x x 0 x 1 x 2 x 3 x 4 x 5 x 6 x 7 X and an edge e ′ of type Z such that I(i e ) = j = I(i e ′ ). Now using Equation 20, for all S ⊆ [d] we obtain:

r z I -1 ( {0,2} ) (x) x 0 z 1 z 2 x 3 x 4 x 5 x 6 z 7
ν I h P ,x,z (S) = ν h P ,x,z (I -1 (S)) ∝ ½(i e ∈ I -1 (S))½(i e ′ / ∈ I -1 (S)) = ½(I(i e ) ∈ S)½(I(i e ′ ) / ∈ S) = ½(j ∈ S)½(j / ∈ S) = 0.
We have just identified two necessary conditions for the Shapley values of ν I to be null: if P contains a type B edge or if the sets I(S X ) and I(S Z ) are not disjoint. We will henceforth assume that none of these conditions apply to P so that the Shapley values are potentially non-null. We now wish to understand what players of ν I are dummies. The following Lemma establishes a relationship between dummies of ν and dummies of ν I .

Lemma 20 If I -1 ({i}) is a set of dummies of ν, then i is a dummy player of ν I . This is true for any games ν and ν I and more specifically Baseline Interventional Games ν h P ,x,z .

Proof First notice that if D ⊆ [d ′ ] is a set of dummy players, then it easily follows by induction that for all S ′ ⊆ [d ′ ] \ D we have ν(S ′ ∪ D) = ν(S ′ ). Now let S ⊆ [d] \ {i} and observe that when I -1 ({i}) is a set of dummy players for ν we have:

ν I (S ∪ {i}) = ν I -1 (S ∪ {i}) = ν I -1 (S) ∪ I -1 ({i}) = ν I -1 (S) = ν I (S)
We now present an analogue to Lemma 11.

Lemma 21 If i does not belong to I(S XZ ), then it is a dummy player for the game ν I h P ,x,z .

Proof If i / ∈ I(S XZ ) then I -1 ({i}) ∩ S XZ = ∅. So by Lemma 11, I -1 ({i}) are dummies of ν h P ,x,z which by Lemma 20 implies that i is a dummy feature of ν I h P ,x,z .

As only the features in S XZ are not dummies of ν h P ,x,z , it follows that ν I h P ,x,z (S) = ν h P ,x,z (I -1 (S) ∩ S XZ ) for all S ⊆ [d].

We will use this fact in the sequel. The following key Theorem shows how to efficiently compute the Shapley values of non-dummy players.

Theorem 22 (Complexity Reduction for Partitions) If P contains no type B edges and the sets I(S X ) and I(S Z ) are disjoint, we get This summation contains an exponential number of terms, and like previous Theorems, only one of these terms will be non-zero. To identify which term is non-zero, we will again rely on Lemma 12. To do so, we note that since I(S X ) and I(S Z ) are disjoint, the sets S X and S Z must also be disjoint. Hence by Lemma 12, we have ν h P ,x,z (S ′ ) = 0 for all S ′ ⊆ S XZ except for S ′ = S X . Since as noted earlier ν I h P ,x,z (S) = ν h P ,x,z (I -1 (S) ∩ S XZ ) for all S ⊆ [d], Lemma 12 ensures that we have the following: ν I h P ,x,z (S) = 0 for all S ⊆ I(S XZ ) except when I -1 (S) ∩ S XZ = S X , or equivalently S = I(S X ). Therefore the only way a difference ν I h P ,x,z (S ∪{i})-ν I h P ,x,z (S) can be non-null is when either S or S ∪{i} is equal to I(S X ). Now, suppose i ∈ I(S X ). The only S ⊆ I(S XZ )\{i} for which the difference ν I h P ,x,z (S ∪ {i})ν I h P ,x,z (S) is not zero is when S = I(S X ) \ {i}. For this set S, we get a contribution

i / ∈ I(S XZ ) ⇒ φ I i (h P , x, z) = 0 (45) i ∈ I(S X ) ⇒ φ I i (h P , x, z) = W (|I(S X )| -1, |I(S XZ )|)v l (46) i ∈ I(S Z ) ⇒ φ I i (h P , x, z) = -W (|I(S X )|, |I(S XZ )|)v l . (47
W (|S|, |I(S XZ )|)v l = W (|I(S X ) \ {i}|, |I(S XZ )|)v l = W (|I(S X )| -1, |I(S XZ )|)v l thus proving Equation 46.
Finally, suppose i ∈ I(S Z ) and so i / ∈ I(S X ). Then the only way the difference ν I h P ,x,z (S ∪ {i})ν I h P ,x,z (S) can be non-null is when S = I(S X ). For this set S, we get a contribution -W (|S|, |I(S XZ )|)v l = -W (|I(S X )|, |I(S XZ )|)v l thus proving Equation 47.

We deduce from Lemma 19 and Theorem 22 that computing Shapley values for the game ν I can be achieved by substituting the sets I(S X ) and I(S Z ) to S X and S Z in the original TreeSHAP algorithm, as shown in Algorithm 4. The simplicity with which we were able to adapt TreeSHAP to partitions is a by-product of the theoretical results we obtained on TreeSHAP. We conclude by noting that if each feature is its own group (i.e. if I(i n ) ∈ I(S X ) then end if 22: end procedure 23: φ = 0; 24: Recurse(0, I(S X ) = ∅, I(S Z ) = ∅); 25: return φ;

Application to Feature Embedding

Classic training procedures for Decision Trees partition the input space at each internal node n via Boolean functions of the form ½(x in ≤ γ n ). However, this model architecture assumes that feature values can be ordered, which always holds for numerical data, but not necessarily for categorical features e.g. x i ∈ [Dog, Cat, Hamster]. In such scenarios, the model architecture itself must be adapted (Hastie et al., 2009, Section 9.2.4), or the categorical features must be embedded in a metric space during pre-processing [START_REF] Guo | Entity embeddings of categorical variables[END_REF]). An efficient approach for computing Interventional Shapley values in such contexts x x 0 x 1 x 2 x 3 ξ(x) x 0 0 1 0 0 1 0 x 3 ξ 0 (x 0 ) ξ 1 (x 1 ) ξ 2 (x 2 ) ξ 3 (x 3 ) I 0 1 1 2 2 2 2 3 • The identity embedding ξ i (x i ) = x i ∈ R 1 is used for numerical features where D i = R.

• The one-hot-encoding ξ i (x i ) = δ x i ∈ R C when x i is categorical and takes C possible values, i.e. D i = [C]. The components of the vector δ j are all 0 except for the jth component which is 1.

• The entity embedding ξ i (x i ) = E[:, i] ∈ R d i where the embedding matrix E ∈ R d i ×C is learned a priori via a Neural Network [START_REF] Guo | Entity embeddings of categorical variables[END_REF].

Letting d ′ = d i=0 d i , we shall also define the global embedding function ξ : R d → R d ′ that maps any given feature vector x to the concatenation ξ(x) = [ξ 0 (x 0 ), . . . , ξ d (x d )] T . Figure 9 shows an example of embedding that relies on a mix of identity embeddings and one-hot encodings. For both training and prediction purposes, the vector ξ(x) stands as the input for the model in place of the feature vector x. Therefore, applying TreeSHAP on the resulting Decision Trees will yield a separate value for each of the d ′ components in the embedded vector. However the d ′ features associated with the embedding lack interpretability and we argue it is more desirable to obtain a Shapley value for each d component of the original vector x. Notice that our embedding ξ induces a surjective function I : [d ′ ] → [d]

Figure 1 :

 1 Figure 1: Example of Shapley values computation.

Figure 2 :

 2 Figure 2: Basic example of Binary Decision Tree. In red we highlight the maximal path followed by the input x = (3.4, 0.2, 2) T .

Figure 3 :

 3 Figure 3: All types of edges in a maximal path P = ( (0, 1), (1, 2), (2, 3), (3, 4) ) from root to leaf.

Figure 4 :

 4 Figure 4: Example of types of edges in a Decision Tree. The input and reference inputs are x = (0, 0, 1) T and z = (-2, -1, 2) T .

Figure 5 :

 5 Figure 5: Example of sets S X = {0, 1} and S Z = {0, 2} for x = (0, 0, 1) T and z = (-2, -1, 2) T .

  Scenario 2: Feature seen before in S Z so go down the direction of z.

Figure 7 :

 7 Figure7: Scenario 3: Feature never seen before in S X and S Z so go down both directions and update S X and S Z accordingly.

)

  Like previously, the Shapley-Taylor indices of non-dummy players follow Definition 14, but where the set of all players [d] is replaced by all non-dummy players D C . Lemma 15 (Dummy Reduction for Shapley-Taylor) Let D ⊆ [d] be the set of all dummy players of the game ν, and D C = [d] \ D be the set of non-dummy players, then

Figure 8 :

 8 Figure 8: The replace function applied to partitions of d ′ = 8 features into d = 4 groups indicated by colors. Importantly, all features in the same group are replaced simultaneously.

)

  Proof The equation 45 is a direct consequence of Lemma 21. We now prove 46 and 47 separately. Since all features in [d] \ I(S XZ ) are dummies of ν I h P ,x,z , we can employ Lemma 2 to rewrite the Shapley value definition φ i (ν I ) = S⊆I(S XZ )\{i} W (|S|, |I(S XZ )| ) ν I h P ,x,z (S ∪{i})-ν I h P ,x,z (S) i ∈ I(S XZ ). (48)

return

  d ′ = d and I(i) = i), Algorithm 4 falls back to Algorithm 2. The coming subsection describes an application of Partition-TreeSHAP. Algorithm 4 Interventional Partition-TreeSHAP 1: procedure Recurse(n, I(S X ), I(S Z )) 2: if n ∈ L then 3: for i ∈ I(S X ) ∪ I(S Z ) do ⊲ cf. Theorem 13 4:if i ∈ I(S X ) then 5:φ i += W (|I(S X )| -1, |I(S XZ )|)v n ; i -= W (|I(S X )|, |I(S XZ )|)v n ; Recurse(x child , I(S X ), I(S Z )); 12:else if I(i n ) ∈ I(S X ) ∪ I(S Z ) then ⊲ Scenario 213:

returnreturn

  Recurse(x child , I(S X ), I(S Z )); Recurse(z child , I(S X ), I(S Z )); child , I(S X ) ∪ I({i n }), I(S Z ));20:Recurse(z child , I(S X ), I(S Z ) ∪ I({i n })); 21:

Figure 9 :

 9 Figure 9: Example of a feature embedding ξ(x) ∈ R 8 . Here, x 0 and x 3 are kept intact while x 1 and x 2 are one-hot-encoded. The bottom of the figure presents the function I that maps the index of an embedded coordinate to the index of its associated x component.

  Assuming d ′ features are fed to the model, let us consider that we partition them in d groups: [d ′ ] = {P i |i ∈ [d]} . This yields a new attribution problem where we wish to associate a real number to each group i ∈ [d] that represents the contribution of the features in P i , when considered as a group, toward the model output. An important application of group attributions is when one-hot encoded categorical features are fed to the Decision Trees. We will discuss this application later in the section. A partition of features [d ′ ] can be conveniently described with an indexing function I : [d ′ ] → [d] that associates each feature j ∈ [d ′

https://github.com/scikit-learn/scikit-learn/pull/12866

https://github.com/gablabc/Understand_TreeSHAP

Acknowledgements

The authors wish to thank the DEEL project CRDPJ 537462-18 funded by the National Science and Engineering Research Council of Canada (NSERC) and the Consortium for Research and Innovation in Aerospace in Québec (CRIAQ), together with its industrial partners Thales Canada inc, Bell Textron Canada Limited, CAE inc and Bombardier inc.

Proof Equations ( 34) and ( 35) are a direct consequence of Lemma 15.

We will first tackle the coefficients Φ ii (h P , x, z) = h P (r z {i} (x))-h P (r z ∅ (x)) with i ∈ S XZ . There are only two possible cases where this difference is non-null. According to Lemma 12, when S X = {i}, we have h P (r z {i} (x))h P (r z ∅ (x)) = h P (r z S X (x))h P (r z ∅ (x)) = v l -0 = v l . When S X = ∅ and i ∈ S Z , we have h P (r z {i} (x))

We have thus proven Equations ( 37) and ( 38). Secondly, we tackle the non-diagonal elements i = j. To reduce the exponential complexity of computing these terms, we must identify the coalitions S ⊆ S XZ \ {i, j} for which

is non-null. Recall that by Lemma 12, h P (r z S (x)) = 0 for all S ⊆ S XZ except for S = S X . So for the contribution of a coalition S to be non-zero, one of S, S ∪ {i}, S ∪ {j} or S ∪ {i, j} must be equal to S X . We distinguish four cases.

If i, j ∈ S X , the only coalition S ⊆ S XZ \ {i, j} for which ∇ ij (S) is non zero is given by S = S X \ {i, j} and

If i, j ∈ S Z , and so i, j / ∈ S X , the only coalition with a non-zero contribution is

If i ∈ S X and j ∈ S Z , the only coalition that contributes to the Shapley-Taylor indices is given by S = S X \ {i}, which leads to

Finally, the case where j ∈ S X and i ∈ S Z is symmetric and leads to the same formula as the previous case. This proves Equations ( 39), ( 40) and ( 41) and concludes the proof.

We present the procedure for efficient computations of Shapley-Taylor indices in Algorithm 3. Note that our results on Interventional TreeSHAP easily apply to these new indices, which we view as a testament to the great value of our mathematical proof for TreeSHAP.

Algorithm 3 Interventional Taylor-TreeSHAP

for j ∈ S X ∪ S Z do 5:

if S X = {i} then 7:

else if S X = ∅ then 9:

Φ ii -= v n ;

10:

else 12:

if i, j ∈ S X then 13:

else 17: Recurse(x child , S X ∪ {i n }, S Z );

32:

Recurse(z child , S X , S Z ∪ {i n });

33:

end if 34: end procedure 35: Φ = zeros(d, d); 36: Recurse(0, S X = ∅, S Z = ∅); 37: return Φ;

given by

where each set P i contains the indices of coordinates corresponding to feature i via the embedding ξ. We therefore propose to use Partition-TreeSHAP with ξ(x), ξ(z) in place of x, z and the mapping I of Equation 49. Doing so will provide a Shapley value for each of the d component of the original vector. Since feature embeddings are not supported in the current implementation of TreeSHAP from the SHAP library, we see Partition-TreeSHAP as a key contribution from a theoretical and practical perspective.

Conclusion

The Interventional TreeSHAP algorithm has previously revolutionized the computation of Shapley values for explaining decision tree ensembles. Indeed, before its invention, the exponential burden of Shapley values severely limited their application to Machine Learning problems, which typically involve large numbers of features. In this work, we take a step back and give a presentation of the mathematics behind the success of Interventional TreeSHAP. In doing so, our goal is both educational and research-oriented. On the one hand, the content of this paper can serve as a reference for a class on the mathematics behind interpretable Machine Learning. To this end, we also provide a simplified C++ implementation of Interventional TreeSHAP wrapped in Python as teaching material for the methods 4 . Our implementation is not meant to rival that of the SHAP library, which makes use of additional computational optimizations at the cost of clarity. On the other hand, we have shown that our theoretical results on Interventional TreeSHAP can be leveraged to effortlessly adapt the Shapley value computations to other game theory indices like Shapley-Taylor indices. Moreover, we have extended Interventional TreeSHAP to tasks where categorical features are embedded in a metric space before being fed to the model. We hope that our proof can stimulate future research in the application of game theory for post-hoc explanations of tree ensembles and similar models such as RuleFits.