0

I am using lightgbm to train LGBM models in R. However, whenever I call lgb.cv() function, lots of warning messages came out.

My code is written as:

train_params <- list(objective = "binary", learning_rate = 0.2, num_leaves = 50L, 
                     bagging_fraction = 0.3,
                     bagging_freq = 10,
                     deterministic = T, force_row_wise = T)

dtrain <- lgb.Dataset(as.matrix(train_data[, vars]), label = as.numeric(train_data[, outcome]), categorical_feature = cat_vars)
lgbm_cv <- lgb.cv(params = train_params, data = dtrain, verbose = -1)

Running the code above gave me the messages like

[LightGBM] [Info] [binary:BoostFromScore]: pavg=0.446809 -> initscore=-0.213574

[LightGBM] [Info] Start training from score -0.213574

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

[LightGBM] [Info] [binary:BoostFromScore]: pavg=0.500000 -> initscore=0.000000

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

[LightGBM] [Info] [binary:BoostFromScore]: pavg=0.553191 -> initscore=0.213574

[LightGBM] [Info] Start training from score 0.213574

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements [LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

[LightGBM] [Warning] No further splits with positive gain, best gain: -inf

[LightGBM] [Warning] Stopped training because there are no more leaves that meet the split requirements

..... (and many more)

These have occupied my console. I saw some discussions mentioned to put -1 for verbose, but it didn't work in my code. Did I miss anything? Is there other way to suppress the warning messages?

Phoebe
  • 53
  • 5

1 Answers1

0
options(warn = -1) # globally suppresses warning messages
options(warn = 0 # to turn them back on

However, global suppression may not be the safest approach so check here for a more nuanced approach.

L Tyrone
  • 1,268
  • 3
  • 15
  • 24
  • I added it and ran it before lgb.cv(). However, it still produced lightGBM warning messages... T_T – Phoebe Mar 23 '23 at 01:26
  • @Phoebe Ah yes, of course. Couldn't test it as you did not `dput()` a sample of your dataset :) Try adding `verbose = -1` to your `lgb.Dataset()` line as well and let me know if that works – L Tyrone Mar 23 '23 at 04:58