Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python xgboost.callback.LearningRateScheduler callback does not work with xgboost.cv() #6701

Closed
trevoryann opened this issue Feb 11, 2021 · 0 comments · Fixed by #6720
Closed

Comments

@trevoryann
Copy link

trevoryann commented Feb 11, 2021

Using the new style callback from xgboost.cv() throws an exception when attempting to change the learning rate. This is with xgboost 1.3.3.

Cut down version of the code:

callbacks = [xgboost.callback.LearningRateScheduler(cb_learning_rate_fn)]
xgb.cv(dict(param), dtrain, n_trees, nfold=nfolds, folds=folds, seed=42,
                             metrics=('auc', 'error', 'logloss'),
                             verbose_eval=False,
                             callbacks=callbacks)

throws an exception:

Traceback (most recent call last):
<top of callstack>
    err_profile = xgb.cv(dict(param), dtrain, n_trees, nfold=nfolds, folds=folds, seed=42,
  File "<venv-dir>/lib/python3.8/site-packages/xgboost/training.py", line 517, in cv
    should_break = callbacks.after_iteration(booster, i, dtrain, None)
  File "<venv-dir>/lib/python3.8/site-packages/xgboost/callback.py", line 428, in after_iteration
    ret = any(c.after_iteration(model, epoch, self.history)
  File "<venv-dir>/lib/python3.8/site-packages/xgboost/callback.py", line 428, in <genexpr>
    ret = any(c.after_iteration(model, epoch, self.history)
  File "<venv-dir>/lib/python3.8/site-packages/xgboost/callback.py", line 458, in after_iteration
    model.set_param('learning_rate', self.learning_rates(epoch))
AttributeError: '_PackedBooster' object has no attribute 'set_param'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants