vignette_titanic_example.Rmd
library("xai2shiny")
DALEX
packages provides an imputed version of a common classification-oriented dataset - titanic
(data was copied from the stablelearner
package). Let’s see a sample of observations:
#> 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
Package allows to pass multiple models from different packages to the main function, so why not create some:
In fact, xai2shiny
function accepts only explainers, i.e. DALEX
special objects basing on provided models. Let’s create all necessary explainers:
After that, the only thing left to do is to generate an app and run it:
xai2shiny(explainer_rf, explainer_glm, directory = './', run = TRUE)
Further cloud deployment can be done in 2 simple steps (see README example for details):
xai2shiny::cloud_setup()
my_droplet_id <- 1 # Compare it to your DigitalOcean account and set a proper ID
deploy_shiny(droplet = my_droplet_id, directory = './xai2shiny', packages = "ranger")
As xai2shiny
covers as many external models sources as DALEX
and DALEXtra
, let’s consider widely known mlr3
package:
library("DALEXtra")
library("mlr3")
library("mlr3learners")
titanic <- titanic_imputed
titanic[, 'survived'] <- as.factor(titanic[, 'survived'])
task <- TaskClassif$new(id = 'titanic',
backend = titanic,
target = "survived",
positive = '1')
learner <- mlr_learners$get('classif.log_reg')
learner$predict_type = "prob"
train_set = sample(task$nrow, 0.8 * task$nrow)
test_set = setdiff(seq_len(task$nrow), train_set)
learner$train(task, row_ids = train_set)
explainer_mlr <- explain_mlr3(learner,
data = titanic[,-8],
y = as.numeric(as.character(titanic$survived)),
label = "mlr3 model")
xai2shiny(explainer_mlr, directory = "./", run = FALSE)