Learn R Programming

iBreakDown (version 0.9.6)

plot.break_down: Plot Generic for Break Down Objects

Description

Plots waterfall break down for objects of the `break_down` class. Usually executed after `break_down()` function, `local_attributions()` or `local_interactions()`.

Usage

# S3 method for break_down
plot(x, ..., baseline = NA, max_features = 10,
  min_max = NA, vcolors = DALEX::theme_drwhy_colors_break_down(),
  digits = 3, rounding_function = round, add_contributions = TRUE,
  shift_contributions = 0.05, plot_distributions = FALSE)

Arguments

x

the model model of `break_down` class.

...

other parameters.

baseline

if numeric then veritical line starts in `baseline`.

max_features

maximal number of features to be included in the plot. default value is 4.

min_max

a range of OX axis. By deafult `NA` therefore will be extracted from the contributions of `x`. But can be set to some constants, usefull if these plots are used for comparisons.

vcolors

named vector with colors.

digits

number of decimal places (`round`) or significant digits (`signif`) to be used. See the rounding_function argument.

rounding_function

function that is to used for rounding numbers. It may be signif which keeps a specified number of significant digits. Or the default round to have the same precision for all components.

add_contributions

shall variable contributions to be added the the plot?

shift_contributions

how much labels sholud be shifted right as a fraction of range. By default 0.05

plot_distributions

if `TRUE` then distributions of conditional propotions will be plotted. This requires keep_distributions=TRUE in the break_down, local_attributions, or local_interactions.

Value

a `ggplot2` object.

References

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

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 <- break_down(explain_titanic_glm, titanic_small[1, ])
bd_rf
plot(bd_rf, max_features = 3)

# }
# NOT RUN {
## Not run:
library("randomForest")
set.seed(1313)
# 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_attributions(explainer_rf,
                           new_observation)
bd_rf
plot(bd_rf)
plot(bd_rf, baseline = 0)
plot(bd_rf, min_max = c(0,1))

bd_rf <- local_attributions(explainer_rf,
                           new_observation,
                           keep_distributions = TRUE)
bd_rf
plot(bd_rf, plot_distributions = TRUE)

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

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

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

bd_rf <- local_attributions(explainer_rf,
                           apartments_test[1,])
bd_rf
plot(bd_rf, digits = 1)
plot(bd_rf, digits = 1, baseline = 0)

bd_rf <- local_attributions(explainer_rf,
                           apartments_test[1,],
                           keep_distributions = TRUE)
plot(bd_rf, plot_distributions = TRUE)

bd_rf <- local_interactions(explainer_rf,
                 new_observation = apartments_test[1,],
                 keep_distributions = TRUE)

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

Run the code above in your browser using DataLab