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

Learning rate decay #4955

Closed
guyko81 opened this issue Oct 16, 2019 · 4 comments · Fixed by #6199
Closed

Learning rate decay #4955

guyko81 opened this issue Oct 16, 2019 · 4 comments · Fixed by #6199

Comments

@guyko81
Copy link

guyko81 commented Oct 16, 2019

I have been thinking about robust model building on Important Outliers - outliers that matters so we don't want the model to add predictions closer to the average value. That led me the idea that implementing a learning rate decay would add the model more flexibility as in the beginning it could catch the trivial rules (a trivial case decision tree in the beginning) due to high learning rate and later in the training it could fine tune the result.

I have made my own GBTree with this additional feature and found that the model learnt much faster as well! Not a big coding but great improvement in performance. I have not tested the robustness (e.g. overfitting) of the model on many datasets but the one I used on showed promising results - no overfit.

I used learning_rate_start=0.5, learning_rate_min=0.01 and lr_decay=0.95.
First iteration:
lr = learning_rate_start
At each iteration afterwards the following rule applies:
lr = max(learning_rate_min, lr*lr_decay)

@trivialfis
Copy link
Member

We have a callback for setting learning rate although I haven't really use it myself. Would it help even simplifying things further?

@guyko81
Copy link
Author

guyko81 commented Oct 16, 2019

My mistake, I was not aware of this callback.
However a rename might be useful, maybe learning_rate_schedule, rather than reset_learning_rate?

And an example code would be nice too.
Should the following work? (I can't try right now, no XGBoost on work computer)

def learning_rate_decay(boosting_round, num_boost_round):
    learning_rate_start = 0.5
    learning_rate_min = 0.01
    lr_decay = 0.95
    lr = learning_rate_start * np.power(lr_decay, boosting_round)
    return max(learning_rate_min, lr)

xgclassifier = xgb.train(params, xgb_dtrain, num_rounds,  callbacks = [xgb.callback.reset_learning_rate(learning_rate_decay)])

and with the new naming (I think it's more obvious):
xgclassifier = xgb.train(params, xgb_dtrain, num_rounds, callbacks = [xgb.callback.learning_rate_schedule(learning_rate_decay)])

@trivialfis
Copy link
Member

@guyko81 Thanks for the suggestion. I agree with your naming scheme, will keep this open so we can have better documentation for callbacks.

@hcho3
Copy link
Collaborator

hcho3 commented Sep 27, 2020

To new contributors: If you're reading this and interested in writing the document for learning rate decay, please comment here. Feel free to ping me with questions. I am available for help.

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.

3 participants