Closed nspyrison closed 1 year ago
Working example combining treeshap and lightgbm examples, maybe something like:
library(treeshap)
library(lightgbm)
#> Loading required package: R6
param_lgbm <- list(objective = "regression", max_depth = 2, force_row_wise = TRUE)
data_fifa <- fifa20$data[!colnames(fifa20$data) %in%
c('work_rate', 'value_eur', 'gk_diving', 'gk_handling',
'gk_kicking', 'gk_reflexes', 'gk_speed', 'gk_positioning')]
## lightgbm on sparse matrix:
lgbm_params <- list(
num_leaves = 4L, learning_rate = 1.0, objective = "binary", nthread = 2L)
fit <- lightgbm(data = as.matrix(data_fifa), params = lgbm_params,
label = fifa20$target, nrounds = 2L)
#> [LightGBM] [Info] Number of positive: 18028, number of negative: 250
#> [LightGBM] [Warning] Auto-choosing col-wise multi-threading, the overhead of testing was 0.004856 seconds.
#> You can set `force_col_wise=true` to remove the overhead.
#> [LightGBM] [Info] Total Bins 3441
#> [LightGBM] [Info] Number of data points in the train set: 18278, number of used features: 48
#> [LightGBM] [Info] [binary:BoostFromScore]: pavg=0.986322 -> initscore=4.278220
#> [LightGBM] [Info] Start training from score 4.278220
#> [1] "[1]: train's binary_logloss:0.100651"
#> [1] "[2]: train's binary_logloss:0.0992022"
## lightgbm on dense matrix:
dat <- na.omit(cbind(data_fifa, fifa20$target))
fit <- lightgbm(data = as.matrix(dat[, -ncol(dat)]), params = lgbm_params,
label = dat[, ncol(dat)], nrounds = 2L)
#> [LightGBM] [Info] Number of positive: 16032, number of negative: 210
#> [LightGBM] [Warning] Auto-choosing row-wise multi-threading, the overhead of testing was 0.001164 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 2956
#> [LightGBM] [Info] Number of data points in the train set: 16242, number of used features: 48
#> [LightGBM] [Info] [binary:BoostFromScore]: pavg=0.987071 -> initscore=4.335234
#> [LightGBM] [Info] Start training from score 4.335234
#> [1] "[1]: train's binary_logloss:0.0975157"
#> [1] "[2]: train's binary_logloss:0.0976132"
Created on 2022-01-05 by the reprex package (v2.0.1)
Thanks! I see that it was already fixed in #25
Following example in ?lightgbm.unify
Created on 2022-01-03 by the reprex package (v2.0.1)