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-package] Where is the code for the 'quantile' objective, and how do I pass a custom objective to LGBMRegressor? #5524

Closed
qinhaohcen opened this issue Oct 7, 2022 · 12 comments
Labels

Comments

@qinhaohcen
Copy link

Description

I want to change quantiles' loss function. Although I can make objective='quantile' , but I can't see a quantile in LGBMRegressor's code. Can you give me some advice? Thank you!

@jameslamb
Copy link
Collaborator

Thanks for using LightGBM! I'm confused a bit by your question.

Which of these are you asking?

  • "how do I provide a custom objective function for quantile regression with LGBMRegressor in the Python package?"
  • "where can I find the code for the quantile objective function, so that I understand how it works?"
  • "what parameters can I use to change the behavior of LightGBM's quantile regression?"

Can you please tell me which of those you're asking?

@qinhaohcen
Copy link
Author

Thank you for your patient reply! I would like to ask for advice on this three points you mentioned.

"how do I provide a custom objective function for quantile regression with LGBMRegressor in the Python package?"
"where can I find the code for the quantile objective function, so that I understand how it works?"
"what parameters can I use to change the behavior of LightGBM's quantile regression?"

@qinhaohcen
Copy link
Author

qinhaohcen commented Oct 8, 2022

Thanks for using LightGBM! I'm confused a bit by your question.

Which of these are you asking?

  • "how do I provide a custom objective function for quantile regression with LGBMRegressor in the Python package?"
  • "where can I find the code for the quantile objective function, so that I understand how it works?"
  • "what parameters can I use to change the behavior of LightGBM's quantile regression?"

Can you please tell me which of those you're asking?

This is my code. When I move the mouse to 'quantite' and press Ctrl+B, I will be prompted to Can't find declaration to go to. But I really want to find out how the quantile method works in LGBMRegressor. And I hope to improve the loss function pinball loss of quantile.
lgb_model_q05 = LGBMRegressor(objective='quantile', metric='quantile', alpha=0.05, learning_rate=0.1, max_depth=7, n_estimators=100)

@jameslamb
Copy link
Collaborator

"how do I provide a custom objective function for quantile regression with LGBMRegressor in the Python package?"

See the Note on custom objectives at the bottom of https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMRegressor.html#lightgbm.LGBMRegressor for information on how to format a custom objective function for LGBMRegressor.

Custom objective functions can be passed to the objective parameter.


"where can I find the code for the quantile objective function, so that I understand how it works?"

the built-in quantile loss is defined here

class RegressionQuantileloss : public RegressionL2loss {


"what parameters can I use to change the behavior of LightGBM's quantile regression?"

The only quantile-specific parameter is alpha (https://lightgbm.readthedocs.io/en/latest/Parameters.html#alpha).

See https://lightgbm.readthedocs.io/en/latest/Parameters.html for descriptions of the other parameters that control LightGBM's behavior.

@jameslamb jameslamb changed the title A Question about Quantile in LGBMRegressor [python-package] Where is the code for the 'quantile' objective, and how do I pass a custom objective to LGBMRegressor? Oct 11, 2022
@qinhaohcen
Copy link
Author

Thank you very much!Now I know why I can't find it.

@qinhaohcen
Copy link
Author

Why is hessian directly assigned to 1.0? Is there any theoretical basis? Can you provide a PDF materials for reference?
``

@qinhaohcen
Copy link
Author

"how do I provide a custom objective function for quantile regression with LGBMRegressor in the Python package?"

See the Note on custom objectives at the bottom of https://lightgbm.readthedocs.io/en/latest/pythonapi/lightgbm.LGBMRegressor.html#lightgbm.LGBMRegressor for information on how to format a custom objective function for LGBMRegressor.

Custom objective functions can be passed to the objective parameter.

"where can I find the code for the quantile objective function, so that I understand how it works?"

the built-in quantile loss is defined here

class RegressionQuantileloss : public RegressionL2loss {

"what parameters can I use to change the behavior of LightGBM's quantile regression?"

The only quantile-specific parameter is alpha (https://lightgbm.readthedocs.io/en/latest/Parameters.html#alpha).

See https://lightgbm.readthedocs.io/en/latest/Parameters.html for descriptions of the other parameters that control LightGBM's behavior.

If you use pinball loss for quantile,gradient(First derivative)should be 1-alpha or alpha. And hessian should be 0.

Did you consider the combination of hessian and lamda and assign hessian as 1?

Sincerely look forward to your answer!

3 similar comments
@qinhaohcen

This comment was marked as duplicate.

@qinhaohcen

This comment was marked as duplicate.

@qinhaohcen

This comment was marked as duplicate.

@jmoralez
Copy link
Collaborator

I believe it's an implementation detail where the sum of the hessians is used as a proxy to the number of samples in a node, but hopefully @shiyu1994 or @guolinke can confirm.

Copy link

This issue has been automatically locked since there has not been any recent activity since it was closed. To start a new related discussion, open a new issue at https://github.com/microsoft/LightGBM/issues including a reference to this.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants