ms_update_observations: Update the observations of a modelStudio object

View source: R/ms_update_observations.R

ms_update_observationsR Documentation

Update the observations of a modelStudio object

Description

This function calculates local explanations on new observations and adds them to the modelStudio object.

Usage

ms_update_observations(
  object,
  explainer,
  new_observation = NULL,
  new_observation_y = NULL,
  max_features = 10,
  B = 10,
  show_info = TRUE,
  parallel = FALSE,
  widget_id = NULL,
  overwrite = FALSE,
  ...
)

Arguments

object

A modelStudio created with modelStudio().

explainer

An explainer created with DALEX::explain().

new_observation

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

new_observation_y

True label for new_observation (optional).

max_features

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

B

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

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.

widget_id

Use an explicit element ID for the widget (rather than an automatically generated one). Useful e.g. when using modelStudio with Shiny. See vignette.

overwrite

Overwrite existing observations and their explanations. Default is FALSE which means add new observations to the existing ones.

...

Other parameters.

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 explanations are implemented in ingredients

  • Break Down and Shapley Values explanations are implemented in iBreakDown

See Also

Vignettes: modelStudio - R & Python examples and modelStudio - perks and features

Examples

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

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

# make a studio for the model
ms <- modelStudio(explainer_titanic,
                  N = 200,  B = 5) # faster example



# add new observations
ms <- ms_update_observations(ms,
                             explainer_titanic,
                             new_observation = titanic_imputed[100:101,],
                             new_observation_y = titanic_imputed$survived[100:101])
ms



# overwrite the observations with new ones
ms <- ms_update_observations(ms,
                             explainer_titanic,
                             new_observation = titanic_imputed[100:101,],
                             overwrite = TRUE)
ms




ModelOriented/modelStudio documentation built on Sept. 2, 2023, 4:49 a.m.