# 8 Break-down Plots for Interactions (iBreak-down Plots)

In Chapter 7, we presented a model-agnostic approach to evaluation of the importance of an explanatory variable for model predictions. An important issue is that, for some models, e.g. models with interactions, the estimated value of the variable-importance measure depends on the ordering of the explanatory variables that is used when computing the measure.

In this chapter, we present an algorithm that addresses the issue. In particular, the algorithm identifies interactions between pairs of variables and takes them into account when constructing Break-down (BD) plots. In our presentation we focus on interactions that involve pairs of explanatory variables, but the algorithm can be easily extended to interactions involving a larger number of variables.

## 8.1 Intuition

Lack of additivness means that the effect of an explanatory variable depends on the value(s) of other variable(s). To illustrate such a situation, we will consider the Titanic dataset (see Section 5.1). For the sake of simplicity, we consider only two variables, age and class. In the data age is a continuous variable, but we will use a dichotomized version of it, with two levels: boys (0-16 years old) and adults (17+ years old). Also, we will consider just two classes: the 2nd and “other”.

Table 8.1 shows percentages of survivors for boys and adult men in the 2nd class and other classes on Titanic. Overall, the proportion of survivors among males is 20.5%. However, among boys in the 2nd class, the proportion is 91.7%. How do age and class contribute to this higher survival probability? Let us consider the following two decompositions.

• Decomposition 1: The overall probability of survival for males is 20.5%, but for the male passengers from the 2nd class the probability is even lower, i.e. 13.5%. Thus, the effect of the 2nd class is negative, as it decreases the probability of survival by 7%. Now, if, for male passengers of the 2nd class, we consider age, we see that the survival probability for boys increases by 78.2%, from 13.5% (for a male in the 2nd class) to 91.7%. Thus, by considering first the effect of the class, and then the effect of age, we can conclude the effect of -7% for the 2nd class and +78.2% for age (being a boy).

• Decomposition 2: The overall probability of survival for males is 20.5%, but for boys the probability is higher, i.e., 40.7%. Thus, the effect of age (being a boy) is positive, as it increases the survival probability by 20.2%. On the other hand, for boys, travelling in the 2nd class increases the probability further, from 40.7% overall to 91.7%. Thus, by considering first the effect of age, and then the effect of class, we can conclude the effect of +20.2% for age (being a boy) and +51% for the 2nd class.

Table 8.1: Proportions of survivors for men on Titanic.
Class Boys (0-16) Adults (>16) Total
2nd 11/12 = 91.7% 13/166 = 7.8% 24/178 = 13.5%
other 22/69 = 31.9% 306/1469 = 20.8% 328/1538 = 21.3%
Total 33/81 = 40.7% 319/1635 = 19.5% 352/1716 = 20.5%

By considering effects of class and age in different order, we get very different contributions. This is because there is an interaction: the effect of class depends on the age and vice versa. In particular, from Table 8.1 we could conclude that the overall effect of 2nd class is negative (-7%), as it decreases the probability of survival from 20.5% to 13.5%. On the other hand, the overall effect of age (being a boy) is positive (+20.2%), as it increases the probability of survival from 20.5% to 40.7%. Based on those effects, we would expect a probability of 20.5%-7%+20.2%=33.7% for a boy in the 2nd class. However, the actually observed proportion is much higher, 90.7%. The difference of 90.7%-33.7%=57% is the interaction effect. We can interpret it as an additional effect of the 2nd class specific for boys, or as an additional effect of age (being a boy) for the 2nd class male passengers.

The example illustrates that interactions complicate the evaluation of the importance of explanatory variables to model predictions. In what follows we present an algorithm to include interactions in the BD plots.

## 8.2 Method

Identification of interactions in the model is performed in three steps (Gosiewska and Biecek 2019a):

1. Calculate the variable-importance measure separately for each explanatory variable. In particular, for each variable, compute $$\Delta^{j|\emptyset}(x_*)$$ (see Section 7.2).
2. Calculate the measure for each pair of variables. Subtract the obtained value from the sum of the measures for the particular variables to obtain a contribution attributable to an interaction. In particular, for each pair of variables, compute $$\Delta^{\{i,j\}|\emptyset}$$ (see Section 7.2) and then

$$$\Delta^{\{i,j\}}_I(x_*) \equiv \Delta^{\{i,j\}|\emptyset}(x_*)-\Delta^{i|\emptyset}(x_*)-\Delta^{j|\emptyset}(x_*). \tag{8.1}$$$

1. Rank the so-obtained importance measures for the main’’ and interaction effects to determine the final ordering for computing the variable-importance measures. Using the ordering, compute variable-importance measures $$v(j, x_*) = \Delta^{j|\{1, ..., j-1\}}(x_*)$$ (see Section 7.2).

The time complexity of the first step is $$O(p)$$, where $$p$$ is the number of explanatory variables. For the second step, the complexity is $$O(p^2)$$, while for the third step it is $$O(p)$$. Thus, the time complexity of the entire procedure is $$O(p^2)$$.

## 8.3 Example: Titanic data

Let us consider the random-forest model titanic_rf_v6 (see Section 5.1.3) and passenger johny_d (see Section 5.1.6) as the instance of interest in the Titanic data.

Table 8.2 presents the expected model predictions $$E_X[f(X)|X^i = x_*^i, X^j = x_*^j]$$, single-variable effects $$\Delta^{\{i,j\}|\emptyset}(x_*)$$ (see Equation (7.5)), and interaction effects $$\Delta_{I}^{\{i,j\}}(x_*)$$ (see Equation (8.1)) for each explanatory variable and each pair of variables. All the measures are calculated for johny_d, the instance of interest. The rows in the table are sorted according to the absolute value of the net impact of the variable or net impact of the interaction between two variables. For a single variable the net impact is simply measured by $$\Delta^{\{i,j\}}(x_*)$$ while for the pairs of variables the net impact is measured by $$\Delta_{I}^{\{i,j\}}(x_*)$$. This way if two variables are important but there is no interaction, then the net effect of interaction $$\Delta_{I}^{\{i,j\}}(x_*)$$ is smaller than additive effect of each variable and the interaction will be lower in the table, see age and gender. Contrary, is the interaction is important then its net effect will be higher than each variable separately, see fare and class.

Based on the ordering of the rows, the following sequence of variables is identified as informative:

• age because it has largest net effect $$0.270$$,
• then fare:class because the net effect of the interaction is $$-0.231$$,
• then gender because its net effect if $$0.125$$ and single variables like class or fare are already used in the interaction,
• then embarked because of its net effect $$-0.011$$,
• then sibsp, and parch as variables with lowest net effects but still larger than effect of their interaction.
Table 8.2: Expected model predictions $$E_X[f(X)|X^i = x_*^i, X^j = x_*^j]$$, single-variable effects $$\Delta^{\{i,j\}|\emptyset}(x_*)$$ (see Equation (7.5)), and interaction effects $$\Delta_{I}^{\{i,j\}}(x_*)$$ (see Equation (8.1)) for the random-forest model titanic_rf_v6 and passenger johny_d in the Titanic data. The rows are sorted according to the absolute value of the net impact of the variable or net impact of the interaction between two variables. For a single variable the net impact is defined as $$\Delta^{\{i,j\}}(x_*)$$ while for the pairs of variables the net impact is equal to $$\Delta_{I}^{\{i,j\}}(x_*)$$.
Variable $$E_X[f(X)|X^{i}= x_*^{i},X^{j}= x_*^{j}]$$ $$\Delta^{\{i,j\}|\emptyset}(x_*)$$ $$\Delta_{I}^{\{i,j\}}(x_*)$$
age 0.505 0.270
fare:class 0.333 0.098 -0.231
class 0.420 0.185
fare:age 0.484 0.249 -0.164
fare 0.379 0.143
gender 0.110 -0.125
age:class 0.591 0.355 -0.100
age:gender 0.451 0.215 0.070
fare:gender 0.280 0.045 0.027
embarked 0.225 -0.011
embarked:age 0.504 0.269 0.010
parch:gender 0.100 -0.136 -0.008
sibsp 0.243 0.008
sibsp:age 0.520 0.284 0.007
sibsp:class 0.422 0.187 -0.006
embarked:fare 0.374 0.138 0.006
sibsp:gender 0.113 -0.123 -0.005
fare:parch 0.380 0.145 0.005
parch:sibsp 0.236 0.001 -0.004
parch 0.232 -0.003
parch:age 0.500 0.264 -0.002
embarked:gender 0.101 -0.134 0.002
embarked:parch 0.223 -0.012 0.001
fare:sibsp 0.387 0.152 0.001
embarked:class 0.409 0.173 -0.001
gender:class 0.296 0.061 0.001
embarked:sibsp 0.233 -0.002 0.001
parch:class 0.418 0.183 0.000

Table 8.3 presents the variable-importance measures computed by using the sequence of variables age, fare:class, gender, embarked, sibsp, and parch.

Table 8.3: Variable-importance measures $$\Delta^{j|\{1,\ldots,j\}}(x_*)$$ computed by using the sequence of variables age, fare:class, gender, embarked, sibsp, and parch for the random-forest model titanic_rf_v6 for the Titanic data and johny_d.
Variable $$\Delta^{j|\{1,\ldots,j\}}(x_*)$$ $$E_X[f(X) | X^{\{1,\ldots,j\}} = x^{\{1,\ldots,j\}}_*)]$$
intercept 0.235
age = 8 0.269 0.505
fare:class = 72:1st 0.039 0.544
gender = male -0.083 0.461
embarked = Southampton -0.002 0.458
sibsp = 0 -0.006 0.452
parch = 0 -0.030 0.422

Figure 8.1 presents the BD plot corresponding to the results from Table 8.3.

As we see the interaction between fare and class is included in the plot as a single bar. As effects of these two variables cannot be disentangled, the plot shows combination of both variables as a single contribution. From Table 8.2 we can read that class alone would increase average prediction by $$0.185$$, fare would increase average prediction by $$0.143$$, but together they increase the average prediction only by $$0.098$$. It’s because the fare=72 is a high value on average, but is below median when it comes for the 1st class passengers. So these two values combined fare:class=72:1st signal a cheaper version of the fist class, this is why its contribution to model prediction is smaller than contribution of class and fare separately.

## 8.4 Pros and cons

iBD plots share many pros and cons of BD plots for models without interactions (see section 7.4). However, in case of interactions, the iBD plots provide more correct explanations.

Though the numerical complexity of the iBD procedure is quadratic, it may be time-consuming in case of models with a large number of explanatory variables. If $$p$$ stands for the number of variables, then we need to estimate $$p*(p+1)/2$$ net effects for single variables and pair of variables. For datasets with small number of observations calculations of net effects will suffer from larger variance and therefore larger randomness in the ranking of effects. The identification of interactions in the presented procedure is not based on a formal statistical significance test. Thus, for small sample sizes, the procedure may be prone to errors.

## 8.5 Code snippets for R

In this section, we use an DALEX() package which is a wrapper for iBreakDown R package (Gosiewska and Biecek 2019a). The package covers all methods presented in this chapter. It is available on CRAN and GitHub.

For illustration purposes, we use the titanic_rf_v6 random-forest model for the Titanic data developed in Section 5.1.3. Recall that it is developed to predict the probability of survival from sinking of Titanic. Instance-level explanations are calculated for a single observation: henry - an 47-years old passenger that travelled in the 1st class.

DALEX explainers for the model and the henry data are retrieved via archivist hooks as listed in Section 5.1.8.

library("randomForest")

henry
##   class gender age sibsp parch fare  embarked
## 1   1st   male  47     0     0   25 Cherbourg

The key function to construct iBD plots is the DALEX::varaible_attribution() function. The use of the function has already been explained in Section 7.5. In order to use Break-down plots the necessary argument is type = "break_down_interactions".

library("DALEX")
new_observation = henry,
type = "break_down_interactions")
bd_rf
##                                             contribution
## Random Forest: intercept                           0.235
## Random Forest: class = 1st                         0.185
## Random Forest: gender = male                      -0.124
## Random Forest: embarked:fare = Cherbourg:25        0.107
## Random Forest: age = 47                           -0.125
## Random Forest: sibsp = 0                          -0.032
## Random Forest: parch = 0                          -0.001
## Random Forest: prediction                          0.246

Now we can plot this object with the generic plot() function.

plot(bd_rf) 

The Figure 8.2 shows iBD plot for henry while Figure 8.1 shows iBD plot for johny_d. In this case different variables were identified as an interaction. As fare=25 for henry is much lower than fare=72 for johny_d effect of class was not modified by fare.

### References

Gosiewska, Alicja, and Przemyslaw Biecek. 2019a. “iBreakDown: Uncertainty of Model Explanations for Non-additive Predictive Models.” https://arxiv.org/abs/1903.11420v1.