How do I turn off debug log output of lightgbm sklearn interface? Tried
regressor = lightgbm.LGBMRegressor(verbose=-1)
does not work.
regressor.fit(verbose=-1)
is not accepted.
What I found is through lightgbm itself, not sklearn interface which I want to use. How can I stop the log output of lightgbm?
Thanks.
Short Answer
These two mechanisms are enough to suppress all log output from
lightgbm's scikit-learn interfaceverbosity=-1to constructor of estimators likeLGBMRegressor()warnings.filterwarnings("ignore", category=UserWarning)Details
With
lightgbm>=4.3.0, just passingverbosity=-1into the constructor should be sufficient.Consider this minimal, reproducible example:
With Python 3.11,
lightgbm==4.3.0, andscikit-learn==1.4.1, that does not produce any log output.The same code but with
verbosity=1instead produces this output:As of
v4.3.0, there is one source of possible log output that cannot be suppressed via theverbositykeyword argument. Any parameters passed intoLGBMRegressor()which don't match its keyword arguments are collected and passed down tolightgbm.train(), andlightgbmsometimes warns when it uses such values.Like this:
Produces this:
You can suppress those using Python's warning-control mechanisms, described in the documentation for the
warningsmodule (docs link).Add this prior to calling any
lightgbmcode: