get_model_specs: Fetches feature information from a given model object

Description Usage Arguments Details Value Author(s) Examples

View source: R/models.R

Description

Fetches feature information from a given model object

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
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

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
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 Jan. 28, 2021, 5:06 p.m.