16
$\begingroup$

I have tried for a while to figure out how to "shut up" LightGBM. Especially, I would like to suppress the output of LightGBM during training (i.e. feedback on the boosting steps).

My model:

params = {
            'objective': 'regression',
            'learning_rate' :0.9,
            'max_depth' : 1,
            'metric': 'mean_squared_error',
            'seed': 7,
            'boosting_type' : 'gbdt'
        }

gbm = lgb.train(params,
                lgb_train,
                num_boost_round=100000,
                valid_sets=lgb_eval,
                early_stopping_rounds=100)

I tried to add verbose=0 as suggested in the docs, but this does not work. https://github.com/microsoft/LightGBM/blob/master/docs/Parameters.rst

Does anyone know how to suppress LightGBM output during training?

$\endgroup$
6
  • 2
    $\begingroup$ Perhaps it's verbose_eval you're looking for? lightgbm.readthedocs.io/en/latest/Python-API.html $\endgroup$
    – bradS
    Commented Jun 17, 2019 at 15:12
  • $\begingroup$ Yep, got rid of most feedback! Thanks! Any idea how I can also suppress warnings, because I still receive a lot of warnings as feedback. $\endgroup$
    – Peter
    Commented Jun 17, 2019 at 15:17
  • 1
    $\begingroup$ What kind of errors are you getting? $\endgroup$
    – bradS
    Commented Jun 17, 2019 at 20:57
  • $\begingroup$ It is „No further splits with positive gain“, likely caused by min_data_in_leaf. However, I would like to keep the configuration. My current application is a parameter search. $\endgroup$
    – Peter
    Commented Jun 17, 2019 at 21:08
  • 1
    $\begingroup$ This is the latest I update on the issue that I can see: github.com/Microsoft/LightGBM/issues/… $\endgroup$
    – bradS
    Commented Jun 17, 2019 at 21:13

5 Answers 5

10
$\begingroup$

As @Peter has suggested, setting verbose_eval = -1 suppresses most of LightGBM output (link: here).

However, LightGBM may still return other warnings - e.g. No further splits with positive gain. This can be suppressed as follows (source: here ):

lgb_train = lgb.Dataset(X_train, y_train, params={'verbose': -1}, free_raw_data=False)
lgb_eval = lgb.Dataset(X_test, y_test, params={'verbose': -1},free_raw_data=False)
gbm = lgb.train({'verbose': -1}, lgb_train, valid_sets=lgb_eval, verbose_eval=False)
$\endgroup$
1
  • $\begingroup$ Indeed, verbose=-1 solves it for the sklearn interface. $\endgroup$ Commented Jul 20 at 23:22
8
$\begingroup$

Solution for sklearn API (checked on v3.3.0):

import lightgbm as lgb


param = {'objective': 'binary', "is_unbalance": 'true',
         'metric': 'average_precision'}
model_skl = lgb.sklearn.LGBMClassifier(**param)

# early stopping and verbosity
# it should be 0 or False, not -1/-100/etc
callbacks = [lgb.early_stopping(10, verbose=0), lgb.log_evaluation(period=0)]

# train
model_skl.fit(x_train, y_train,
              eval_set=[(x_train, y_train), (x_val, y_val)],
              eval_names=['train', 'valid'],
              eval_metric='average_precision',
              callbacks=callbacks)
$\endgroup$
1
  • 1
    $\begingroup$ Confirmed. log_evaluation(0) is the important piece for turning off the booster updates. $\endgroup$ Commented Dec 15, 2021 at 0:16
7
$\begingroup$

To suppress (most) output from LightGBM, the following parameter can be set.

Suppress warnings: 'verbose': -1 must be specified in params={}.

Suppress output of training iterations: verbose_eval=False must be specified in the train{} parameter.

Minimal example:

params = {
            'objective': 'regression',
            'learning_rate' : 0.9, 
            'max_depth' : 1, 
            'metric': 'mean_squared_error',
            'seed': 7,
            'verbose': -1,
            'boosting_type' : 'gbdt'
        }

gbm = lgb.train(params,
                lgb_train,
                num_boost_round=100000,
                valid_sets=lgb_eval,
                verbose_eval=False,
                early_stopping_rounds=100)
$\endgroup$
4
$\begingroup$

Follow these points.

  1. Use verbose= False in fit method.
  2. Use verbose= -100 when you call the classifier.
  3. Keep silent = True (default).
$\endgroup$
1
$\begingroup$

I read all the answers and issues, and tried all these approaches and yet LGBM still outputs some info (which drives me crazy). If you want to completely suppress any output during the training try this out:

with open(os.devnull, "w") as f, contextlib.redirect_stdout(f):
    gbm = lgb.cv(param, lgb_dataset)
$\endgroup$
1
  • $\begingroup$ This was the only way it worked right now. Thanks. $\endgroup$
    – igorkf
    Commented Feb 15, 2023 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.