You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Since nrounds is not a supported alias for num_iterations in LightGBM, it is not possible to override the default value of nrounds in lgb.train() or lightgbm() by passing nrounds as part of the list in params.
As @mikemahoney218 noted in #4226 (comment), this is confusing behavior. Everywhere else in the R and Python packages, LightGBM treats values in params as higher-precedence than those passed through keyword arguments.
This behavior also adds friction to hyperparameter tuning (and will add even more once the suggestions from #4226 are fully implemented), as it makes nrounds a training parameter that cannot be altered by altering the list in params.
nrounds should be added as an alias for num_iterations in LightGBM.
Reproducible example
library(lightgbm)
data(agaricus.train, package="lightgbm")
dtrain<-lightgbm::lgb.Dataset(
agaricus.train$data
, label=agaricus.train$label
)
bst<-lightgbm::lgb.train(
params=list(
"nrounds"=17
, "objective"="regression"
)
, data=dtrain
)
# should be 17, but 100 boosting rounds were performedbst$current_iter()
# [1] 100
How to fix this
Add nrounds to the list of aliases for num_iterations at
To ensure that other interfaces to LightGBM besides the R package respect this parameter alias, update the relevant C++ code and documentation. See https://github.com/microsoft/LightGBM/pull/4637/files for reference of which files should be changed. Do not edit docs/Parameters.rst directly... run python helpers/parameter_generator.py from the root of the repo after updating files in include/ and src/.
No problem, thanks for the report! @mikemahoney218 are you interested in contributing this change? I'd be happy to help answer any questions about the contribution process.
Description
In the R package,
lgb.train()
andlightgbm()
expose a keyword argumentnrounds
, an integer indicating how many boosting rounds should be performed.{lightgbm}
uses the value of that argument to setnum_iteration
, unlessnum_iterations
or another alias for it (https://lightgbm.readthedocs.io/en/latest/Parameters.html#num_iterations) is provided in the keyword argumentparams
.LightGBM/R-package/R/lgb.train.R
Lines 111 to 115 in 798dc1d
Since
nrounds
is not a supported alias fornum_iterations
in LightGBM, it is not possible to override the default value ofnrounds
inlgb.train()
orlightgbm()
by passingnrounds
as part of the list inparams
.As @mikemahoney218 noted in #4226 (comment), this is confusing behavior. Everywhere else in the R and Python packages, LightGBM treats values in
params
as higher-precedence than those passed through keyword arguments.This behavior also adds friction to hyperparameter tuning (and will add even more once the suggestions from #4226 are fully implemented), as it makes
nrounds
a training parameter that cannot be altered by altering the list inparams
.nrounds
should be added as an alias fornum_iterations
in LightGBM.Reproducible example
How to fix this
Add
nrounds
to the list of aliases fornum_iterations
atLightGBM/R-package/R/aliases.R
Lines 108 to 119 in 798dc1d
To ensure that other interfaces to LightGBM besides the R package respect this parameter alias, update the relevant C++ code and documentation. See https://github.com/microsoft/LightGBM/pull/4637/files for reference of which files should be changed. Do not edit
docs/Parameters.rst
directly... runpython helpers/parameter_generator.py
from the root of the repo after updating files ininclude/
andsrc/
.Add a unit test to https://github.com/microsoft/LightGBM/blob/798dc1d4191b93fd34797d62b79c66cd95209406/R-package/tests/testthat/test_basic.R which confirms that
{lightgbm}
respectsnrounds
passed throughparameters
.Additional Comments
@StrikerRUS @Laurae2 please let me know if you disagree with this idea or have any additional thoughts to add.
The text was updated successfully, but these errors were encountered: