This function computes various (instance and dataset level) model explanations and produces an interactive, customisable dashboard. It consists of multiple panels for plots with their short descriptions. Easily save and share the HTML dashboard with others. Tools for model exploration unite with tools for EDA (Exploratory Data Analysis) to give a broad overview of the model behavior.

Theoretical introduction to the plots: Explanatory Model Analysis: Explore, Explain and Examine Predictive Models

modelStudio(explainer, ...)

# S3 method for explainer
modelStudio(
  explainer,
  new_observation = NULL,
  new_observation_y = NULL,
  facet_dim = c(2, 2),
  time = 500,
  max_features = 10,
  N = 300,
  B = 10,
  eda = TRUE,
  show_info = TRUE,
  parallel = FALSE,
  options = ms_options(),
  viewer = "external",
  ...
)

Arguments

explainer

An explainer created with DALEX::explain().

...

Other parameters.

new_observation

New observations with columns that correspond to variables used in the model.

new_observation_y

True label for new_observation (optional).

facet_dim

Dimensions of the grid. Default is c(2,2).

time

Time in ms. Set the animation length. Default is 500.

max_features

Maximum number of features to be included in BD and SV plots. Default is 10.

N

Number of observations used for the calculation of PD and AD. 10*N is a number of observations used for the calculation of FI. Default N is 300. See vignette

B

Number of permutation rounds used for calculation of SV and FI. Default is 10. See vignette

eda

Compute EDA plots. Default is TRUE.

show_info

Verbose a progress on the console. Default is TRUE.

parallel

Speed up the computation using parallelMap::parallelMap(). See vignette. This might interfere with showing progress using show_info.

options

Customize modelStudio. See ms_options and vignette.

viewer

Default is external to display in an external RStudio window. Use browser to display in an external browser or internal to use the RStudio internal viewer pane for output.

Value

An object of the r2d3, htmlwidget, modelStudio class.

References

  • The input object is implemented in DALEX

  • Feature Importance, Ceteris Paribus, Partial Dependence and Accumulated Dependence plots are implemented in ingredients

  • Break Down and Shapley Values plots are implemented in iBreakDown

See also

Examples

library("DALEX")
library("modelStudio")

#:# ex1 classification on 'titanic' data

# fit a model
model_titanic <- glm(survived ~., data = titanic_imputed, family = "binomial")

# create an explainer for the model
explainer_titanic <- explain(model_titanic,
                             data = titanic_imputed,
                             y = titanic_imputed$survived,
                             label = "Titanic GLM")

# pick observations
new_observations <- titanic_imputed[1:2,]
rownames(new_observations) <- c("Lucas","James")

# make a studio for the model
modelStudio(explainer_titanic,
            new_observations)

# \donttest{

#:# ex2 regression on 'apartments' data
library("ranger")

model_apartments <- ranger(m2.price ~. ,data = apartments)

explainer_apartments <- explain(model_apartments,
                                data = apartments,
                                y = apartments$m2.price)

new_apartments <- apartments[1:2,]
rownames(new_apartments) <- c("ap1","ap2")

# change dashboard dimensions and animation length
modelStudio(explainer_apartments,
            new_apartments,
            facet_dim = c(2, 3),
            time = 800)

# add information about true labels
modelStudio(explainer_apartments,
            new_apartments,
            new_observation_y = new_apartments$m2.price)

# don't compute EDA plots
modelStudio(explainer_apartments,
            eda = FALSE)


#:# ex3 xgboost model on 'HR' dataset
library("xgboost")

HR_matrix <- model.matrix(status == "fired" ~ . -1, HR)

# fit a model
xgb_matrix <- xgb.DMatrix(HR_matrix, label = HR$status == "fired")
params <- list(max_depth = 3, objective = "binary:logistic", eval_metric = "auc")
model_HR <- xgb.train(params, xgb_matrix, nrounds = 300)

# create an explainer for the model
explainer_HR <- explain(model_HR,
                        data = HR_matrix,
                        y = HR$status == "fired",
                        label = "xgboost")

# pick observations
new_observation <- HR_matrix[1:2, , drop=FALSE]
rownames(new_observation) <- c("id1", "id2")
# make a studio for the model
modelStudio(explainer_HR,
            new_observation)

# }