calculate_ice: Calculate individual conditional expectations for list of...

Description Usage Arguments Value Examples

Description

Given a list of models, get their predictions over a range of values from a specified feature. This is done by copying an input matrix X several times and replacing a specified feature with different values for each copy. The list of models then make predictions on this modified data.

Usage

1
2
3
4
calculate_ice(feature_dt, feature_col, model_list, num_grid = 10,
  custom_range = NULL, predict_fcn = predict,
  ensemble_colname = "ensemble", ensemble_fcn = median,
  ensemble_models = names(model_list))

Arguments

feature_dt

data.table containing features used in predictive model

feature_col

character. name of a column in feature_dt

model_list

named list of model objects. Each name will become a column containing predictions from that model.

num_grid

number of points to distribute along range of feature_col or custom_range

custom_range

should only be used if feature_cols is a 1-element vector Defines a custom range to calculate partial dependency over. This can be a 2-element numerical vector or a character vector, depending on the type of feature_cols[1]

predict_fcn

function that accepts a model as its first argument and newdata as one of its named arguments

ensemble_colname

character. Name of the column containing ensemble predictions

ensemble_fcn

function that combines a vector of predictions into a single ensemble. Default is median

ensemble_models

character vector of names from model_list. These models will be combined by ensemble_fcn to form the ensemble

Value

Output is a data.table of the same structure as feature_dt, with several changes:

  1. feature_dt is copied num_grid or length(custom_range) times

  2. the values in feature_col will have been modified

  3. new columns will have been added. One for each value in model_list as well as ensemble_colname

  4. an id column will have been added to track observations

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
## Not run: 
dt <- data.table(a = 1:3, b = 2:4, c = c(8, 11, 14))
m <- lm(c ~ a + b - 1, dt)
gm <- glm(c ~ a + b - 1, data = dt)
calculate_ice(dt, "a", list(lm1 = m),
              num_grid = 6)
calculate_ice(dt, "a", list(lm1 = m, glm1 = gm),
              num_grid = 6, ensemble_fcn = sum)
calculate_ice(dt, "a", list(lm1 = m),
              num_grid = 6, custom_range = c(1,6))

## End(Not run)

breather/brightbox documentation built on May 13, 2019, 5:04 a.m.