# \donttest{
setLGBMthreads(2L)
data.table::setDTthreads(1L)
Logit <- function(x) {
log(x / (1.0 - x))
}
data(agaricus.train, package = "lightgbm")
labels <- agaricus.train$label
dtrain <- lgb.Dataset(
agaricus.train$data
, label = labels
)
set_field(
dataset = dtrain
, field_name = "init_score"
, data = rep(Logit(mean(labels)), length(labels))
)
data(agaricus.test, package = "lightgbm")
params <- list(
objective = "binary"
, learning_rate = 0.1
, max_depth = -1L
, min_data_in_leaf = 1L
, min_sum_hessian_in_leaf = 1.0
, num_threads = 2L
)
model <- lgb.train(
params = params
, data = dtrain
, nrounds = 5L
)
tree_interpretation <- lgb.interprete(
model = model
, data = agaricus.test$data
, idxset = 1L:5L
)
lgb.plot.interpretation(
tree_interpretation_dt = tree_interpretation[[1L]]
, top_n = 3L
)
# }
Run the code above in your browser using DataLab