Learn R Programming

modelStudio (version 0.2.1)

modelStudio: Generate Interactive Studio with Explanations for the Model

Description

This tool uses your model, data and new observations, to provide local and global explanations. It generates plots and descriptions in the form of the serverless HTML site, that supports animations and interactivity made with D3.js.

Find more details about plots in Explanatory Model Analysis: Explore, Explain and Examine Predictive Models

Usage

modelStudio(object, ...)

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

# S3 method for default modelStudio( object, data, y, predict_function = predict, label = class(model)[1], new_observation = NULL, new_observation_y = NULL, facet_dim = c(2, 2), time = 500, max_features = 10, N = 400, B = 15, show_info = TRUE, parallel = FALSE, options = modelStudioOptions(), viewer = "external", ... )

Arguments

object

An explainer created with function DALEX::explain() or a model to be explained.

...

Other parameters.

new_observation

A new observation with columns that correspond to variables used in the model.

new_observation_y

True label for new_observation.

facet_dim

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

time

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

max_features

Maximum number of features to be included in Break Down and SHAP Values plots. Default is 10.

N

Number of observations used for calculation of partial dependency profiles. Default is 400.

B

Number of random paths used for calculation of SHAP values. Default is 15.

show_info

Verbose progress bar on the console. Default is TRUE.

parallel

Speed up the computation using parallelMap::parallelMap(). See vignette.

options

Customize modelStudio. See modelStudioOptions 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.

data

Validation dataset, will be extracted from object if it is an explainer. NOTE: It is best when target variable is not present in the data.

y

True labels for data, will be extracted from object if it is an explainer.

predict_function

Predict function, will be extracted from object if it is an explainer.

label

A name of the model, will be extracted from object if it is an explainer.

Value

An object of the r2d3 class.

References

  • Wrapper for the function is implemented in DALEX

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

  • Break Down and SHAP Values plots are implemented in iBreakDown

See Also

Python wrappers and more can be found in DALEXtra

Examples

Run this code
# NOT RUN {
library("modelStudio")

# ex1 classification

model_titanic_glm <- glm(survived ~.,
                         data = DALEX::titanic_imputed,
                         family = "binomial")

explain_titanic_glm <- DALEX::explain(model_titanic_glm,
                                      data = DALEX::titanic_imputed[,-8],
                                      y = DALEX::titanic_imputed[,8],
                                      label = "glm",
                                      verbose = FALSE)

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

modelStudio(explain_titanic_glm, new_observations,
            N = 100, B = 10, show_info = FALSE)

# }
# NOT RUN {
# ex2 regression

model_apartments <- glm(m2.price ~. ,
                        data = DALEX::apartments)

explain_apartments <- DALEX::explain(model_apartments,
                                     data = DALEX::apartments[,-1],
                                     y = DALEX::apartments[,1],
                                     verbose = FALSE)

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

modelStudio(explain_apartments, new_apartments,
            facet_dim = c(2, 3), time = 1000,
            show_info = FALSE)

modelStudio(explain_apartments, show_info = FALSE)
modelStudio(explain_apartments, new_observation = new_apartments,
                                new_observation_y = DALEX::apartments[1:2, 1],
                                show_info = FALSE)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab