This function deploys an explainer as an REST API with an corresponding swagger. A new folder will be created in your working directory containing a plumber R file and an .rda file of the explainer. Deployment can be done either locally or directly to the DigitalOcean's droplet. Full guide on setting up DigitalOcean's droplet and deploying to the cloud can be found on package's GitHub page.

deploy_explainer(
  exp_name,
  model_package,
  droplet = NA,
  port = 8088,
  deploy = TRUE,
  title = "xai2cloud"
)

Arguments

exp_name

DALEX explainer object or an .rda filename in your working directory containing the explainer

model_package

Name of package used to build the model, eg: "randomForest", "gbm".

droplet

If you want to deploy the API locally leave the value as NA. If you want to deploy to DigitalOcean, use the droplet's ID which can be checked by using analogsea::droplets()

port

Port on which you want your API to be deployed

deploy

Boolean telling whether the plumber file is run on set port

title

Title to be seen in Swagger

Examples

# Create a model library("ranger") library("DALEX")
#> Welcome to DALEX (version: 1.2.1). #> Find examples and detailed introduction at: https://pbiecek.github.io/ema/ #> Additional features will be available after installation of: ggpubr. #> Use 'install_dependencies()' to get all suggested dependencies
model <- ranger(survived~., data = titanic_imputed) # Create DALEX explainer explainer <- explain(model, data = titanic_imputed[,-8], y = titanic_imputed$survived)
#> Preparation of a new explainer is initiated #> -> model label : ranger ( default ) #> -> data : 2207 rows 7 cols #> -> target variable : 2207 values #> -> model_info : package ranger , ver. 0.12.1 , task regression ( default ) #> -> predict function : yhat.ranger will be used ( default ) #> -> predicted values : numerical, min = 0.008119304 , mean = 0.3220239 , max = 0.9921745 #> -> residual function : difference between y and yhat ( default ) #> -> residuals : numerical, min = -0.78242 , mean = 0.0001329206 , max = 0.8842242 #> A new explainer has been created!
# Deploy the API # If you want the API to deploy automatically, set deploy parameter to TRUE # Locally deploy_explainer(explainer, model_package = "ranger", port = 8070, deploy=FALSE, title = "Local Example")
#> Warning: 'exp_name' already exists
#> #> Attaching package: ‘ingredients’
#> The following objects are masked from ‘package:iBreakDown’: #> #> describe, plotD3
#> The following object is masked from ‘package:DALEX’: #> #> feature_importance
# To the cloud if (FALSE) { my_droplets <- analogsea::droplets() # Choose the correct droplets name - xai2cloudExamples in this case specific_droplet <- my_droplets$xai2cloudExamples droplet_id <- specific_droplet$id deploy_explainer(explainer, model_package = "ranger", droplet = droplet_id, port = 8070, title = "Titanic Example") }