importance: Importance of variables and interactions in the model

Description Usage Arguments Details Value Examples

View source: R/importance.R

Description

This functions calculates a table with selected measures of importance for variables and interactions.

Usage

1
importance(xgb_model, data, option = "both", digits = 4)

Arguments

xgb_model

a xgboost or lightgbm model.

data

a data table with data used to train the model.

option

if "variables" then table includes only single variables, if "interactions", then only interactions if "both", then both single variable and interactions. Default "both".

digits

number of significant digits that shall be returned. Will be passed to the signif() functions.

Details

Available measures:

Additionally for table with single variables:

Value

a data table

Examples

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

imp <- importance(xgb_model, sm, option = "both")
imp
plot(imp,  top = 10)

imp <- importance(xgb_model, sm, option = "variables")
imp
plot(imp,  top = nrow(imp))

 imp <- importance(xgb_model, sm, option = "interactions")
 imp
plot(imp,  top =  nrow(imp))

 imp <- importance(xgb_model, sm, option = "variables")
 imp
plot(imp, top = NULL, radar = FALSE, xmeasure = "sumCover", ymeasure = "sumGain")

EIX documentation built on March 23, 2021, 9:06 a.m.