nano_interaction: Variable Interaction

View source: R/nano_interaction.R

nano_interactionR Documentation

Variable Interaction

Description

Calculated pair-wise variable interaction in a predictive model.

Usage

nano_interaction(nano, model_no = nano$n_model, vars, plot = FALSE)

Arguments

nano

object containing models to calculate interactions from.

model_no

the positions of each model in the list of models in the nano object for which the interactions should be calculated. If not entered, the last model is taken by default.

vars

a character vector of variables to calculate pair-wise interactions for.

plot

a logical specifying whether plots of the interactions should be created.

Details

The interactions are calculated by the Friedman's H-statistic (square root of the H -squared test statistic) and takes on values between 0 (no interaction) to 1 (100% of standard deviation of f(x) du to interaction). This package uses the Interaction function from the iml package to calculate the H-statistic. Please see their manual for more details.

For the variables specified in the vars argument, this funtion calculates the interaction for each pair-wise interaction of that variable with every other variable used as a predictor for the specified model.

Value

nano object with interactions of specified models calculated. Also returns a plot if plot = TRUE.

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)
 
 obj <- create_nano(grid = list(grid_1),
                    data = list(property_prices),  
                    ) # since model is not entered, will take best model from grids
 
 # calculate all pair-wise interactions for the variable "lot_size"
 nano <- nano_interaction(nano, 1, "lot_size", FALSE) 
 
 }

## End(Not run)

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