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" )
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 |
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 |
#>#> #> #>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#> #>#>#> #>#>#> #># 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") }