Instance Level Variable Attributions as Break Down or SHAP 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. Find information how to use this function here: https://pbiecek.github.io/ema/breakDown.html.

predict_parts(explainer, new_observation, ..., type = "break_down")

predict_parts_oscillations(explainer, new_observation, ...)

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, ..., type = "break_down")

Arguments

explainer

a model to be explained, preprocessed by the 'explain' function

new_observation

a new observarvation for which predictions need to be explained

...

other parameters that will be passed to iBreakDown::break_down

type

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

Value

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

References

Explanatory Model Analysis. Explore, Explain and Examine Predictive Models. https://pbiecek.github.io/ema/

Examples

new_dragon <- data.frame(year_of_birth = 200, height = 80, weight = 12.5, scars = 0, number_of_lost_teeth = 5) dragon_lm_model4 <- lm(life_length ~ year_of_birth + height + weight + scars + number_of_lost_teeth, data = dragons) dragon_lm_explainer4 <- explain(dragon_lm_model4, data = dragons, y = dragons$year_of_birth, label = "model_4v")
#> Preparation of a new explainer is initiated #> -> model label : model_4v #> -> data : 2000 rows 8 cols #> -> target variable : 2000 values #> -> predict function : yhat.lm will be used ( default ) #> -> predicted values : numerical, min = 541.1056 , mean = 1370.986 , max = 3928.189 #> -> model_info : package stats , ver. 4.0.0 , task regression ( default ) #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -5421.316 , mean = -1450.523 , max = 1176.912 #> A new explainer has been created!
dragon_lm_predict4 <- predict_parts_break_down(dragon_lm_explainer4, new_observation = new_dragon) head(dragon_lm_predict4)
#> contribution #> model_4v: intercept 1370.986 #> model_4v: scars = 0 -397.300 #> model_4v: number_of_lost_teeth = 5 -302.277 #> model_4v: height = 80 -9.734 #> model_4v: year_of_birth = 200 -6.639 #> model_4v: weight = 12.5 -0.973
plot(dragon_lm_predict4)
# \dontrun{ library("ranger") dragon_ranger_model4 <- ranger(life_length ~ year_of_birth + height + weight + scars + number_of_lost_teeth, data = dragons, num.trees = 50) dragon_ranger_explainer4 <- explain(dragon_ranger_model4, data = dragons, y = dragons$year_of_birth, label = "model_ranger")
#> Preparation of a new explainer is initiated #> -> model label : model_ranger #> -> data : 2000 rows 8 cols #> -> target variable : 2000 values #> -> predict function : yhat.ranger will be used ( default ) #> -> predicted values : numerical, min = 587.0422 , mean = 1369.233 , max = 3422.757 #> -> model_info : package ranger , ver. 0.12.1 , task regression ( default ) #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -4993.757 , mean = -1448.77 , max = 1036.165 #> A new explainer has been created!
dragon_ranger_predict4 <- predict_parts_break_down(dragon_ranger_explainer4, new_observation = new_dragon) head(dragon_ranger_predict4)
#> contribution #> model_ranger: intercept 1369.233 #> model_ranger: scars = 0 -346.437 #> model_ranger: number_of_lost_teeth = 5 -301.967 #> model_ranger: height = 80 31.319 #> model_ranger: year_of_birth = 200 21.162 #> model_ranger: weight = 12.5 8.270
plot(dragon_ranger_predict4)
# }