predict_parts function

Instance Level Parts of the Model Predictions

Instance Level Parts of the Model Predictions

Instance Level Variable Attributions as Break Down, SHAP, aggregated 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. aSHAP method provides explanations for a set of observations based on SHAP.

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, ...) predict_parts_shap_aggregated(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, aggregated_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.

Returns

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

Examples

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) 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)

References

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

  • Maintainer: Przemyslaw Biecek
  • License: GPL
  • Last published: 2023-01-15

Downloads (last 30 days):