LightGBM tuner raises exception while tuning if initial lgbm parameters contain max_depth=-1.
This error is caused by the following code:
https://github.com/optuna/optuna/blob/master/optuna/integration/lightgbm_tuner/optimize.py#L215-L218
max_depth = self.lgbm_params.get('max_depth', 8)
self.lgbm_params['num_leaves'] = trial.suggest_int(
'num_leaves', 2, 2 ** max_depth)
-1 is a default parameter in LightGBM.
https://github.com/optuna/optuna/issues/870#issue-556544694
If max_depth<=0 is specified, optuna should fallback to its internal default (=8).
ValueError: The `low` value must be smaller than or equal to the `high` value (low=2, high=0.5).
import optuna
import optuna.integration.lightgbm as lgb
from sklearn.datasets import make_classification
from sklearn.model_selection import train_test_split
X, y = make_classification()
X_train, X_valid, y_train, y_valid = train_test_split(X, y)
dtrain = lgb.Dataset(X_train, y_train)
dvalid = lgb.Dataset(X_valid, y_valid)
params = {
'objective': 'binary',
'max_depth': -1
}
lgb.train(params, dtrain, valid_sets=[dvalid], verbose_eval=-1)
Thanks @nyanp for the report! I created a PR (https://github.com/optuna/optuna/pull/872) to resolve this issue. Please let me know if you have any comments.
@smly Thanks for your very quick response! The PR looks good to me :)
Thank you for reporting @nyanp!
As #872 is merged, let me close this issue.