Optuna: LightGBM tuner raises exception when max_depth=-1

Created on 29 Jan 2020  路  3Comments  路  Source: optuna/optuna

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)

Expected behavior

-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).

Environment

  • Optuna version: 1.0.0
  • Python version: 3.7
  • OS: Mac OS

Error messages, stack traces, or logs

ValueError: The `low` value must be smaller than or equal to the `high` value (low=2, high=0.5).

Reproducible examples

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)
bug

All 3 comments

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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

superluminance picture superluminance  路  4Comments

dwiel picture dwiel  路  4Comments

uvinetz picture uvinetz  路  3Comments

mateuszpieniak picture mateuszpieniak  路  3Comments

CMobley7 picture CMobley7  路  3Comments