Learn R Programming

flashlight (version 0.9.0)

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. The size of the tree can be modified by passing ... arguments to rpart::rpart().

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 = 4L, ... )

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

Value

An object of class "light_global_surrogate" with the following elements:

  • data A tibble with results. Can be used to build fully customized visualizations. Column names can be controlled by options(flashlight.column_name).

  • by Same as input by.

Arguments

x

An object of class "flashlight" or "multiflashlight".

...

Arguments passed to rpart::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::rpart() to take too long to split non-numeric variables with many levels.

Methods (by class)

  • light_global_surrogate(default): Default method not implemented yet.

  • light_global_surrogate(flashlight): Surrogate model for a flashlight.

  • light_global_surrogate(multiflashlight): Surrogate model for a multiflashlight.

References

Molnar C. (2019). Interpretable Machine Learning.

See Also

plot.light_global_surrogate()

Examples

Run this code
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