| lgb.interprete {lightgbm} | R Documentation |
Computes feature contribution components of rawscore prediction.
lgb.interprete(model, data, idxset, num_iteration = NULL)
model |
object of class |
data |
a matrix object or a dgCMatrix object. |
idxset |
a integer vector of indices of rows needed. |
num_iteration |
number of iteration want to predict with, NULL or <= 0 means use best iteration. |
For regression, binary classification and lambdarank model, a list of data.table with the following columns:
Feature Feature names in the model.
Contribution The total contribution of this feature's splits.
For multiclass classification, a list of data.table with the Feature column and Contribution columns to each class.
Sigmoid <- function(x) 1 / (1 + exp(-x))
Logit <- function(x) log(x / (1 - x))
data(agaricus.train, package = "lightgbm")
train <- agaricus.train
dtrain <- lgb.Dataset(train$data, label = train$label)
setinfo(dtrain, "init_score", rep(Logit(mean(train$label)), length(train$label)))
data(agaricus.test, package = "lightgbm")
test <- agaricus.test
params <- list(
objective = "binary"
, learning_rate = 0.01
, num_leaves = 63
, max_depth = -1
, min_data_in_leaf = 1
, min_sum_hessian_in_leaf = 1
)
model <- lgb.train(params, dtrain, 20)
tree_interpretation <- lgb.interprete(model, test$data, 1:5)