Learn R Programming

DALEX (version 2.4.1)

predict_parts: Instance Level Parts of the Model Predictions

Description

Instance Level Variable Attributions as Break Down, SHAP or Oscillations explanations. Model prediction is decomposed into parts that are attributed for particular variables. From DALEX version 1.0 this function calls the break_down or shap functions from the iBreakDown package or ceteris_paribus from the ingredients package. Find information how to use the break_down method here: https://ema.drwhy.ai/breakDown.html. Find information how to use the shap method here: https://ema.drwhy.ai/shapley.html. Find information how to use the oscillations method here: https://ema.drwhy.ai/ceterisParibusOscillations.html.

Usage

predict_parts(
  explainer,
  new_observation,
  ...,
  N = if (substr(type, 1, 4) == "osci") 500 else NULL,
  type = "break_down"
)

predict_parts_oscillations(explainer, new_observation, ...)

predict_parts_oscillations_uni( explainer, new_observation, variable_splits_type = "uniform", ... )

predict_parts_oscillations_emp( explainer, new_observation, variable_splits = NULL, variables = colnames(explainer$data), ... )

predict_parts_break_down(explainer, new_observation, ...)

predict_parts_break_down_interactions(explainer, new_observation, ...)

predict_parts_shap(explainer, new_observation, ...)

variable_attribution( explainer, new_observation, ..., N = if (substr(type, 1, 4) == "osci") 500 else NULL, type = "break_down" )

Arguments

explainer

a model to be explained, preprocessed by the explain function

new_observation

a new observation for which predictions need to be explained

...

other parameters that will be passed to iBreakDown::break_down

N

the maximum number of observations used for calculation of attributions. By default NULL (use all) or 500 (for oscillations).

type

the type of variable attributions. Either shap, oscillations, oscillations_uni, oscillations_emp, break_down or break_down_interactions.

variable_splits_type

how variable grids shall be calculated? Will be passed to ceteris_paribus.

variable_splits

named list of splits for variables. It is used by oscillations based measures. Will be passed to ceteris_paribus.

variables

names of variables for which splits shall be calculated. Will be passed to ceteris_paribus.

Value

Depending on the type there are different classes of the resulting object. It's a data frame with calculated average response.

References

Explanatory Model Analysis. Explore, Explain, and Examine Predictive Models. https://ema.drwhy.ai/

Examples

Run this code
# NOT RUN {
library(DALEX)

new_dragon <- data.frame(
    year_of_birth = 200,
    height = 80,
    weight = 12.5,
    scars = 0,
    number_of_lost_teeth  = 5
)

model_lm <- lm(life_length ~ year_of_birth + height +
               weight + scars + number_of_lost_teeth,
               data = dragons)

explainer_lm <- explain(model_lm,
                        data = dragons,
                        y = dragons$year_of_birth,
                        label = "model_lm")

bd_lm <- predict_parts_break_down(explainer_lm, new_observation = new_dragon)
head(bd_lm)
plot(bd_lm)

# }
# NOT RUN {
library("ranger")
model_ranger <- ranger(life_length ~ year_of_birth + height +
                       weight + scars + number_of_lost_teeth,
                       data = dragons, num.trees = 50)

explainer_ranger <- explain(model_ranger,
                            data = dragons,
                            y = dragons$year_of_birth,
                            label = "model_ranger")

bd_ranger <- predict_parts_break_down(explainer_ranger, new_observation = new_dragon)
head(bd_ranger)
plot(bd_ranger)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab