This report aims to present the capabilities of the package live.

The document is a part of the paper “Landscape of R packages for eXplainable Machine Learning”, S. Maksymiuk, A. Gosiewska, and P. Biecek. (https://arxiv.org/abs/2009.13248). It contains a real life use-case with a hand of titanic_imputed data set described in Section Example gallery for XAI packages of the article.

We did our best to show the entire range of the implemented explanations. Please note that the examples may be incomplete. If you think something is missing, feel free to make a pull request at the GitHub repository MI2DataLab/XAI-tools.

The list of use-cases for all packages included in the article is here.

Load titanic_imputed data set.

data(titanic_imputed, package = "DALEX")

head(titanic_imputed)
##   gender age class    embarked  fare sibsp parch survived
## 1   male  42   3rd Southampton  7.11     0     0        0
## 2   male  13   3rd Southampton 20.05     0     2        0
## 3   male  16   3rd Southampton 20.05     1     1        0
## 4 female  39   3rd Southampton 20.05     1     1        1
## 5 female  16   3rd Southampton  7.13     0     0        1
## 6   male  25   3rd Southampton  7.13     0     0        1
library(live)
library(ggplot2)
set.seed(123)

Fit a random forest to the titanic imputed data.

rf_model <- ranger::ranger(survived~., data = titanic_imputed, classification = TRUE, probability = TRUE)

Predict parts

LIVE explanation

similar <- sample_locally(data = titanic_imputed,
                          explained_instance = titanic_imputed[1, ],
                          explained_var = "survived",
                          size = 500)

pred_fun <- function(X.model, newdata) {
  predict(X.model, newdata)$predictions[,2]
}
similar1 <- add_predictions(to_explain = similar,
                            black_box_model = rf_model,
                            predict_fun = pred_fun)
explanation <- fit_explanation(live_object = similar1,
                             white_box = "regr.lm")
plot(explanation, type = "forest")

similar <- sample_locally(data = titanic_imputed,
                          explained_instance = titanic_imputed[13, ],
                          explained_var = "survived",
                          size = 500)
pred_fun <- function(X.model, newdata) {
  predict(X.model, newdata)$predictions[,2]
}
similar1 <- add_predictions(to_explain = similar,
                            black_box_model = rf_model,
                            predict_fun = pred_fun)
explanation <- fit_explanation(live_object = similar1,
                             white_box = "regr.lm")

plot(explanation, type = "waterfall") + ylim(0.33, 0.47)

Session info

sessionInfo()
## R version 3.6.1 (2019-07-05)
## Platform: x86_64-w64-mingw32/x64 (64-bit)
## Running under: Windows 10 x64 (build 18362)
## 
## Matrix products: default
## 
## locale:
## [1] LC_COLLATE=Polish_Poland.1250  LC_CTYPE=Polish_Poland.1250   
## [3] LC_MONETARY=Polish_Poland.1250 LC_NUMERIC=C                  
## [5] LC_TIME=Polish_Poland.1250    
## 
## attached base packages:
## [1] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
## [1] ggplot2_3.3.2 live_1.5.13  
## 
## loaded via a namespace (and not attached):
##  [1] Rcpp_1.0.4.6      lattice_0.20-40   RWeka_0.4-42      tidyr_1.0.2      
##  [5] class_7.3-15      assertthat_0.2.1  digest_0.6.25     mime_0.9         
##  [9] R6_2.4.1          ranger_0.12.1     backports_1.1.8   stats4_3.6.1     
## [13] evaluate_0.14     pillar_1.4.4      RWekajars_3.9.3-2 rlang_0.4.6      
## [17] data.table_1.12.8 Matrix_1.2-18     forestmodel_0.6.2 checkmate_2.0.0  
## [21] rmarkdown_2.1     labeling_0.3      splines_3.6.1     mda_0.5-2        
## [25] stringr_1.4.0     munsell_0.5.0     shiny_1.4.0.2     broom_0.5.6      
## [29] compiler_3.6.1    httpuv_1.5.2      xfun_0.12         ParamHelpers_1.13
## [33] pkgconfig_2.0.3   breakDown_0.1.6   mlr_2.17.0        BBmisc_1.11      
## [37] htmltools_0.4.0   tidyselect_1.0.0  tibble_3.0.1      XML_3.99-0.3     
## [41] crayon_1.3.4      dplyr_0.8.5       withr_2.2.0       later_1.0.0      
## [45] grid_3.6.1        nlme_3.1-140      xtable_1.8-4      gtable_0.3.0     
## [49] lifecycle_0.2.0   magrittr_1.5      scales_1.1.1      stringi_1.4.6    
## [53] farver_2.0.3      promises_1.1.0    parallelMap_1.4   ellipsis_0.3.1   
## [57] vctrs_0.3.1       generics_0.0.2    fastmatch_1.1-0   tools_3.6.1      
## [61] glue_1.4.1        purrr_0.3.3       parallel_3.6.1    fastmap_1.0.1    
## [65] survival_3.1-11   yaml_2.2.1        colorspace_1.4-1  rJava_0.9-13     
## [69] knitr_1.28        modeltools_0.2-23