nano_multi_ice: Calculates ICE for multiple models

nano_multi_iceR Documentation

Calculates ICE for multiple models

Description

Calculates initial conditional expectations (ICEs) from multiple h2o models.

Usage

nano_multi_ice(
  models,
  data,
  vars,
  max_levels = 30,
  quantiles = seq(0, 1, 0.1),
  target = NULL
)

Arguments

models

a list of h2o models.

data

a dataset. Dataset used to create model.

vars

vector of characters. Vector containing variables in data to create ICEs

max_levels

a numeric. Maximum number of unique levels to calculate ICE for each variable.

quantiles

a numeric vector of quantiles (numbers from 0 to 1) for each ICE to be calculated for.

targets

a character vector. Only applicable for classification models. Subset of levels of response variables which ICE should be calculated for.

Details

Creates a list of data.tables. Each data.table corresponds to the calculated ICEs values from a single model. In each data.table, contains the ICEs values for each variable combined together into a single data.table.

For creating ICEs, it is recommended to instead use the nano_ice function which is a wrapper for a series of functions which creates ICEs. It is able to create ICEs directly from a nano object, for both single and multi models, and has the option to return plots of the ICEs.

Value

a list of data.tables containing the calculated ICEs for each model. Each data.table has the outputs for each variable in vars combined into the one data.table.

Examples

## Not run: 
if(interactive()){
 library(h2o)
 library(nano)
 
 h2o.init()
 
 # import dataset
 data(property_prices)
 train <- as.h2o(property_prices)
 
 # set the response and predictors
 response <- "sale_price"
 var <- setdiff(colnames(property_prices), response)
 
 # build grids
 grid_1 <- h2o.grid(x               = var,
                    y               = response,
                    training_frame  = train,
                    algorithm       = "randomForest",
                    hyper_params    = list(ntrees = 1:2),
                    nfolds          = 3,
                    seed            = 628)

 grid_2 <- h2o.grid(x               = var,
                    y               = response,
                    training_frame  = train,
                    algorithm       = "randomForest",
                    hyper_params    = list(ntrees = 3:4),
                    nfolds          = 3,
                    seed            = 628)
 
 model_1 <- h2o.getModel(grid_1@model_ids[[1]])
 model_2 <- h2o.getModel(grid_2@model_ids[[1]])
 
 # calculate ICE
 nano_multi_ice(models    = list(model_1, model_2), 
                data      = list(property_prices), 
                vars      = c("lot_size", "income"),
                quantiles = seq(0, 1, 0.1))
 
 }

## End(Not run)

Nanoputian628/nano documentation built on Oct. 30, 2023, 3:28 p.m.