get_model_specs: Fetches feature information from a given model object

View source: R/models.R

get_model_specsR Documentation

Fetches feature information from a given model object

Description

Fetches feature information from a given model object

Usage

get_model_specs(x)

## Default S3 method:
get_model_specs(x)

## S3 method for class 'lm'
get_model_specs(x)

## S3 method for class 'glm'
get_model_specs(x)

## S3 method for class 'gam'
get_model_specs(x)

## S3 method for class 'ranger'
get_model_specs(x)

## S3 method for class 'xgb.Booster'
get_model_specs(x)

Arguments

x

Model object for the model to be explained.

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.

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)

Author(s)

Martin Jullum

Examples

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

shapr documentation built on May 4, 2023, 5:10 p.m.