Learn R Programming

EIX (version 1.2.0)

interactions: Importance of interactions and pairs in the model

Description

This function calculates a table with two measures of importance for interactions and pairs in the model.

Usage

interactions(xgb_model, data, option = "interactions")

Arguments

xgb_model

a xgboost or lightgbm model.

data

a data table with data used to train the model.

option

if "interactions", the table contains interactions, if "pairs", this table contains all the pairs in the model. Default "interactions".

Value

a data table

Details

Available measures:

  • "sumGain" - sum of Gain value in all nodes, in which given variable occurs,

  • "freqency" - number of occurrences in the nodes for given variable.

NOTE: Be careful use of this function with option="pairs" parameter, because high gain of pair can be a result of high gain of child variable. As strong interactions should be considered only these pairs of variables, where variable on the bottom (child) has higher gain than variable on the top (parent).

Examples

Run this code
# NOT RUN {
library("EIX")
library("Matrix")
sm <- sparse.model.matrix(left ~ . - 1,  data = HR_data)

library("xgboost")
param <- list(objective = "binary:logistic", max_depth = 2)
xgb_model <- xgboost(sm, params = param, label = HR_data[, left] == 1, nrounds = 25, verbose=0)

inter <- interactions(xgb_model, sm, option = "interactions")
inter
plot(inter)

inter <- interactions(xgb_model, sm, option = "pairs")
inter
plot(inter)

# }
# NOT RUN {
library(lightgbm)
train_data <- lgb.Dataset(sm, label =  HR_data[, left] == 1)
params <- list(objective = "binary", max_depth = 2)
lgb_model <- lgb.train(params, train_data, 25)

inter <- interactions(lgb_model, sm, option = "interactions")
inter
plot(inter)

inter <- interactions(lgb_model, sm, option = "pairs")
inter
plot(inter)
# }
# NOT RUN {
# }

Run the code above in your browser using DataLab