iBreakDown (version 0.9.6)

local_interactions: Model Agnostic Sequential Variable Attributions with Interactions

Description

This function implements decomposition of model predictions with identification of interactions. The complexity of this function is O(2*p) for additive models and O(2*p^2) for interactions. This function works in a similar way to step-up and step-down greedy approximations in function `breakDown::break_down()`. The main difference is that in the first step the order of variables and interactions is determined. And in the second step the impact is calculated.

Usage

local_interactions(x, ...)

# S3 method for explainer local_interactions(x, new_observation, keep_distributions = FALSE, ...)

# S3 method for default local_interactions(x, data, predict_function = predict, new_observation, label = class(x)[1], keep_distributions = FALSE, order = NULL, interaction_preference = 1, ...)

Arguments

x

a model to be explained, or an explainer created with function `DALEX::explain()`.

...

other parameters.

new_observation

a new observation with columns that correspond to variables used in the model.

keep_distributions

if `TRUE`, then the distribution of partial predictions is stored in addition to the average.

data

validation dataset, will be extracted from `x` if it's an explainer.

predict_function

predict function, will be extracted from `x` if it's an explainer.

label

character - the name of the model. By default it's extracted from the 'class' attribute of the model.

order

if not `NULL`, then it will be a fixed order of variables. It can be a numeric vector or vector with names of variables/interactions.

interaction_preference

a constant that set the preference for interactions. By default `1`. The larger the more frequently interactions will be presented in explanations.

Value

an object of the `break_down` class.

References

Predictive Models: Visual Exploration, Explanation and Debugging https://pbiecek.github.io/PM_VEE

See Also

break_down, local_attributions

Examples

Run this code
# NOT RUN {
library("DALEX")
library("iBreakDown")
# Toy examples, because CRAN angels ask for them
titanic <- na.omit(titanic)
set.seed(1313)
titanic_small <- titanic[sample(1:nrow(titanic), 500), c(1,2,6,9)]
model_titanic_glm <- glm(survived == "yes" ~ gender + age + fare,
                       data = titanic_small, family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
                           data = titanic_small[,-9],
                           y = titanic_small$survived == "yes")

bd_rf <- local_interactions(explain_titanic_glm, titanic_small[1, ], interaction_preference = 500)
bd_rf
plot(bd_rf, max_features = 2)

# }
# NOT RUN {
library("DALEX")
# example with interaction
# classification for HR data
model <- randomForest(status ~ . , data = HR)
new_observation <- HR_test[1,]

explainer_rf <- explain(model,
                 data = HR[1:1000,1:5],
                 y = HR$status[1:1000])

bd_rf <- local_interactions(explainer_rf,
                 new_observation)

bd_rf
plot(bd_rf)

# example for regression - apartment prices
# here we do not have intreactions
model <- randomForest(m2.price ~ . , data = apartments)
explainer_rf <- explain(model,
         data = apartments_test[1:1000,2:6],
         y = apartments_test$m2.price[1:1000])

new_observation <- apartments_test[1,]

bd_rf <- local_interactions(explainer_rf,
                 new_observation,
                 keep_distributions = TRUE)

bd_rf
plot(bd_rf)
plot(bd_rf, plot_distributions = TRUE)
# }

Run the code above in your browser using DataLab