Computes feature contribution components of rawscore prediction.

lgb.interprete(model, data, idxset, num_iteration = NULL)



object of class lgb.Booster.


a matrix object or a dgCMatrix object.


an integer vector of indices of rows needed.


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.


# \donttest{ Logit <- function(x) log(x / (1.0 - 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.1 , max_depth = -1L , min_data_in_leaf = 1L , min_sum_hessian_in_leaf = 1.0 ) model <- lgb.train( params = params , data = dtrain , nrounds = 3L )
#> [LightGBM] [Info] Number of positive: 3140, number of negative: 3373 #> [LightGBM] [Warning] Auto-choosing row-wise multi-threading, the overhead of testing was 0.000962 seconds. #> You can set `force_row_wise=true` to remove the overhead. #> And if memory is not enough, you can set `force_col_wise=true`. #> [LightGBM] [Info] Total Bins 232 #> [LightGBM] [Info] Number of data points in the train set: 6513, number of used features: 116 #> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf #> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf #> [LightGBM] [Warning] No further splits with positive gain, best gain: -inf
tree_interpretation <- lgb.interprete(model, test$data, 1L:5L) # }