Giter VIP home page Giter VIP logo

xai2shiny's Introduction

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:

  • directory - a location indicator where to create whole xai2shiny directory and place there required files (an app and explainers),
  • selected_variables - a vector containing variables list chosen at an app start-up (used for modification and local explanations research),
  • run - whether to run an app immediately after creating.

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)
  • size - ram size desired for the droplet, defaults to 1GB. It can be modified later through DigitalOceans website.

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")
  • droplet - the droplet object/droplet's ID that can be read from running analogsea::droplets().
  • path - path to the xai2shiny application
  • packages - packages used to create or run the model, they will be installed on the droplet.

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)
    • Break Down plot
    • SHAP values plot
    • Ceteris Paribus plot
  4. Global explanations:
    • Feature importance plots
    • 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.