README.md

xai2shiny

R build status Coverage Status

Overview

The xai2shiny R package creates a Shiny application for Explainers (adapters for machine learning models created using the DALEX package). Turn your model into an interactive application containing model's prediction, performance and many XAI methods with just one function. Furthermore, with xai2shiny you can simply export your application to the cloud and share it with others.

Installation

# Install the development version from GitHub:
devtools::install_github("ModelOriented/xai2shiny")

Example

Package usage example will be based on the titanic dataset, including GLM and Random Forest models. The final application created using the scipt below. First, it is necessary to have any explainers created whatsoever:

library("xai2shiny")
library("ranger")
library("DALEX")

# Creating ML models
model_rf <- ranger(survived ~ .,
                   data = titanic_imputed,
                   classification = TRUE, 
                   probability = TRUE)
model_glm <- glm(survived ~ .,
                 data = titanic_imputed,
                 family = "binomial")

# Creating DALEX explainers
explainer_rf <- explain(model_rf,
                     data = titanic_imputed[,-8],
                     y = titanic_imputed$survived)

explainer_glm <- explain(model_glm,
                     data = titanic_imputed[,-8],
                     y = titanic_imputed$survived)

Then all is left to do is to run:

xai2shiny::xai2shiny(explainer_glm, explainer_rf, 
                     directory = './',
                     selected_variables = c('gender', 'age'),
                     run = FALSE)

Above, in xai2shiny function, apart from explainers, following attributes were provided:

Cloud deployment

Further cloud deployment can be performed. In order to do so, there are just three steps necessary to enjoy your new xai2shiny application in the cloud.

  1. If you don't have an account on DigitalOcean, create one here and get $100 free credit.
  2. Create an SSH key if you don't have one yet.
  3. Deploy the SSH key to DigitalOcean

And that's it, you are ready to get back to R and deploy your application. In order to create a new cloud instance, called a droplet by DigitalOcean, running Docker on Ubuntu with all prerequisities installed, just run:

xai2shiny::cloud_setup(size)

Now that your droplet is setup, just deploy the created xai2shiny application with one function.

deploy_shiny(droplet = <your_droplet_id>, path = './xai2shiny', packages = "ranger")

And that's it, the xai2shiny application is running and will automatically open in your default web browser, now all that's left is to share it!

Functionality

The main function is called xai2shiny which creates the Shiny app.R file and runs it converting your models into an interactive application.

At the time it supports such functionalities for multiple models in one application:

  1. Model prediction
  2. Model performance (with text descriptions of measures)
  3. Local explanations: (with text descriptions)
  4. Break Down plot
  5. SHAP values plot
  6. Ceteris Paribus plot
  7. Global explanations:
  8. Feature importance plots
  9. Partial Dependence plots

Acknowledgments

Work on this package was financially supported by the Polish National Science Centre under Opus Grant number 2017/27/B/ST6/0130.



ModelOriented/xai2shiny documentation built on Jan. 30, 2021, 3:02 a.m.