Learn R Programming

shapr (version 0.2.2)

get_model_specs: Fetches feature information from a given model object

Description

Fetches feature information from a given model object

Usage

get_model_specs(x)

# S3 method for default get_model_specs(x)

# S3 method for lm get_model_specs(x)

# S3 method for glm get_model_specs(x)

# S3 method for gam get_model_specs(x)

# S3 method for ranger get_model_specs(x)

# S3 method for xgb.Booster get_model_specs(x)

Value

A list with the following elements:

labels

character vector with the feature names to compute Shapley values for

classes

a named character vector with the labels as names and the class type as elements

factor_levels

a named list with the labels as names and character vectors with the factor levels as elements (NULL if the feature is not a factor)

Arguments

x

Model object for the model to be explained.

Author

Martin Jullum

Details

This function is used to extract the feature information to be checked against data passed to shapr and explain. The function is called from preprocess_data.

Examples

Run this code
if (requireNamespace("MASS", quietly = TRUE)) {
  # Load example data
  data("Boston", package = "MASS")
  # Split data into test- and training data
  x_train <- data.table::as.data.table(head(Boston))
  x_train[, rad := as.factor(rad)]
  model <- lm(medv ~ lstat + rm + rad + indus, data = x_train)

  get_model_specs(model)
}

Run the code above in your browser using DataLab