Plots waterfall break down for objects of the break_down class.

plotD3(x, ...)

# S3 method for break_down
plotD3(
  x,
  ...,
  baseline = NA,
  max_features = 10,
  digits = 3,
  rounding_function = round,
  bar_width = 12,
  margin = 0.2,
  scale_height = FALSE,
  min_max = NA,
  vcolors = NA,
  chart_title = NA,
  time = 0
)

Arguments

x

an explanation created with break_down

...

other parameters.

baseline

if numeric then veritical line will start in baseline.

max_features

maximal number of features to be included in the plot. By default it's 10.

digits

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

rounding_function

a function to be used for rounding numbers. This should be signif which keeps a specified number of significant digits or round (which is default) to have the same precision for all components.

bar_width

width of bars in px. By default it's 12px

margin

extend x axis domain range to adjust the plot. Usually value between 0.1 and 0.3, by default it's 0.2

scale_height

if TRUE, the height of the plot scales with window size

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

If NA (default), DrWhy colors are used.

chart_title

a character. Set custom title

time

in ms. Set the animation length

Value

a r2d3 object.

References

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

Examples

library("DALEX") library("iBreakDown") 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", label = "glm")
#> Preparation of a new explainer is initiated #> -> model label : glm #> -> data : 500 rows 4 cols #> -> target variable : 500 values #> -> model_info : package stats , ver. 3.6.1 , task regression ( default ) #> -> predict function : yhat.glm will be used ( default ) #> -> predicted values : numerical, min = 0.111212 , mean = 0.298 , max = 0.9430377 #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -0.789032 , mean = 1.799189e-14 , max = 0.8594593 #> A new explainer has been created!
bd_glm <- local_attributions(explain_titanic_glm, titanic_small[1, ]) bd_glm
#> contribution #> glm: intercept 0.298 #> glm: gender = male -0.103 #> glm: age = 50 -0.038 #> glm: fare = 13 -0.005 #> glm: survived = no 0.000 #> glm: prediction 0.152
plotD3(bd_glm) # \donttest{ ## Not run: library("randomForest") m_rf <- randomForest(status ~ . , data = HR[2:2000,]) new_observation <- HR_test[1,] new_observation
#> gender age hours evaluation salary status #> 1 male 57.72683 42.31527 2 2 fired
p_fun <- function(object, newdata){predict(object, newdata=newdata, type = "prob")} bd_rf <- local_attributions(m_rf, data = HR_test, new_observation = new_observation, predict_function = p_fun) bd_rf
#> contribution #> randomForest.formula.fired: intercept 0.378 #> randomForest.formula.fired: hours = 42.32 0.215 #> randomForest.formula.fired: evaluation = 2 0.061 #> randomForest.formula.fired: salary = 2 -0.163 #> randomForest.formula.fired: age = 57.73 0.223 #> randomForest.formula.fired: gender = male 0.165 #> randomForest.formula.fired: status = fired 0.000 #> randomForest.formula.fired: prediction 0.878 #> randomForest.formula.ok: intercept 0.281 #> randomForest.formula.ok: hours = 42.32 -0.031 #> randomForest.formula.ok: evaluation = 2 0.087 #> randomForest.formula.ok: salary = 2 0.165 #> randomForest.formula.ok: age = 57.73 -0.230 #> randomForest.formula.ok: gender = male -0.163 #> randomForest.formula.ok: status = fired 0.000 #> randomForest.formula.ok: prediction 0.110 #> randomForest.formula.promoted: intercept 0.341 #> randomForest.formula.promoted: hours = 42.32 -0.184 #> randomForest.formula.promoted: evaluation = 2 -0.149 #> randomForest.formula.promoted: salary = 2 -0.002 #> randomForest.formula.promoted: age = 57.73 0.007 #> randomForest.formula.promoted: gender = male -0.002 #> randomForest.formula.promoted: status = fired 0.000 #> randomForest.formula.promoted: prediction 0.012
plotD3(bd_rf) # }