Plots Shapley values.

# S3 method for shap
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,
  max_vars = NULL,
  reload = FALSE
)

Arguments

x

an explanation created with shap

...

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

max_vars

alias for the max_features parameter.

reload

Reload the plot on resize. By default it's FALSE.

Value

a r2d3 object.

References

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

Examples

library("DALEX")
library("iBreakDown")
set.seed(1313)
model_titanic_glm <- glm(survived ~ gender + age + fare,
                       data = titanic_imputed, family = "binomial")
explain_titanic_glm <- explain(model_titanic_glm,
                           data = titanic_imputed,
                           y = titanic_imputed$survived,
                           label = "glm")
#> Preparation of a new explainer is initiated
#>   -> model label       :  glm 
#>   -> data              :  2207  rows  8  cols 
#>   -> target variable   :  2207  values 
#>   -> predict function  :  yhat.glm  will be used (  default  )
#>   -> predicted values  :  No value for predict function target column. (  default  )
#>   -> model_info        :  package stats , ver. 4.1.2 , task classification (  default  ) 
#>   -> predicted values  :  numerical, min =  0.1490412 , mean =  0.3221568 , max =  0.9878987  
#>   -> residual function :  difference between y and yhat (  default  )
#>   -> residuals         :  numerical, min =  -0.8898433 , mean =  4.198546e-13 , max =  0.8448637  
#>   A new explainer has been created!  

s_glm <- shap(explain_titanic_glm, titanic_imputed[1, ])
s_glm
#>                                     min          q1      median        mean
#> glm: age = 42               -0.01514903 -0.01492541 -0.01434645 -0.01447369
#> glm: class = 3rd             0.00000000  0.00000000  0.00000000  0.00000000
#> glm: embarked = Southampton  0.00000000  0.00000000  0.00000000  0.00000000
#> glm: fare = 7.11            -0.01823177 -0.01784977 -0.01784977 -0.01772034
#> glm: gender = male          -0.10843751 -0.10725651 -0.10725651 -0.10725871
#> glm: parch = 0               0.00000000  0.00000000  0.00000000  0.00000000
#> glm: sibsp = 0               0.00000000  0.00000000  0.00000000  0.00000000
#> glm: survived = 0            0.00000000  0.00000000  0.00000000  0.00000000
#>                                      q3         max
#> glm: age = 42               -0.01396446 -0.01396446
#> glm: class = 3rd             0.00000000  0.00000000
#> glm: embarked = Southampton  0.00000000  0.00000000
#> glm: fare = 7.11            -0.01738588 -0.01705077
#> glm: gender = male          -0.10725293 -0.10667755
#> glm: parch = 0               0.00000000  0.00000000
#> glm: sibsp = 0               0.00000000  0.00000000
#> glm: survived = 0            0.00000000  0.00000000
plotD3(s_glm)
# \dontrun{ ## Not run: library("randomForest") HR_small <- HR[2:500,] m_rf <- randomForest(status ~. , data = HR_small) 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")} s_rf <- shap(m_rf, data = HR_small[,-6], new_observation = new_observation, predict_function = p_fun) plotD3(s_rf, time = 500)
# }