Learn R Programming

flashlight (version 0.7.5)

light_global_surrogate: Global Surrogate Tree

Description

Model predictions are modelled by a single decision tree, serving as an easy to interprete surrogate to the original model. As suggested in Molnar (see reference below), the quality of the surrogate tree can be measured by its R-squared.

Usage

light_global_surrogate(x, ...)

# S3 method for default light_global_surrogate(x, ...)

# S3 method for flashlight light_global_surrogate( x, data = x$data, by = x$by, v = NULL, use_linkinv = TRUE, n_max = Inf, seed = NULL, keep_max_levels = 4, label_name = "label", tree_name = "tree", ... )

# S3 method for multiflashlight light_global_surrogate(x, ...)

Arguments

x

An object of class flashlight or multiflashlight.

...

Arguments passed to rpart, such as maxdepth.

data

An optional data.frame.

by

An optional vector of column names used to additionally group the results. For each group, a separate tree is grown.

v

Vector of variables used in the surrogate model. Defaults to all variables in data except "by", "w" and "y".

use_linkinv

Should retransformation function be applied? Default is TRUE.

n_max

Maximum number of data rows to consider to build the tree.

seed

An integer random seed used to select data rows if n_max is lower than the number of data rows.

keep_max_levels

Number of levels of categorical and factor variables to keep. Other levels are combined to a level "Other". This prevents rpart to take too long to split non-numeric variables with many levels.

label_name

Column name in resulting data containing the label of the flashlight. Defaults to "label".

tree_name

Column name in resulting data containing the trees. Defaults to "tree".

Value

An object of class light_global_surrogate, light (and a list) with the following elements.

  • data A tibble with results. Can be used to build fully customized visualizations.

  • by Same as input by.

  • label_name Same as input label_name.

  • tree_name Name of column with tree objects.

Methods (by class)

  • default: Default method not implemented yet.

  • flashlight: Surrogate model for a flashlight.

  • multiflashlight: Surrogate model for a multiflashlight.

Details

The size of the tree can be modified by passing ... arguments to rpart.

References

Molnar C. (2019). Interpretable Machine Learning.

See Also

plot.light_global_surrogate.

Examples

Run this code
# NOT RUN {
fit <- lm(Sepal.Length ~ ., data = iris)
x <- flashlight(model = fit, label = "lm", data = iris)
light_global_surrogate(x)

# }

Run the code above in your browser using DataLab