Repository navigation
[dask] add support for custom objective functions (fixes #3934) - #4920
Conversation
|
One of the new tests,
Pushed 8b78419 to increase |
|
@ffineis if you have time / interest I'd welcome your thoughts on this PR too π |
|
@jameslamb I left some suggestions on the multi-class objective function to try to get about the same score as the built-in one. Was that your intention? |
Co-authored-by: JosΓ© Morales <jmoralz92@gmail.com>
Thanks very much @jmoralez ! I think you caught some critical mistakes in my implementation. My goal isn't to perfectly replicate the built-in one, just to have something good enough to use in unit tests to build confidence that the Dask estimators are handling custom objective functions correctly. |
StrikerRUS
left a comment
There was a problem hiding this comment.
Thanks for working on this! I have a few number of minor suggestions below:
Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
It has failed again in |
I think this multiclass objective I've added has numeric stability problems. I'll experiment a bit. |
|
In #4925 I'm testing that objective function against the built-in and seems to be working ok. Maybe increasing the learning rate to 0.1 could mimic the results from |
903c0ad to
54df09e
Compare
|
I noticed that Linux Azure Pipelines CI jobs started to timeout randomly two or three days ago. |
Thanks for letting me know! Looks like that is what happened here as well. By the way... @jmoralez @StrikerRUS I pushed changes to this PR last night and I think it's ready for another review. See the diff in 54df09e. I found the following issues that were causing the multiclass classification tests to fail:
I ran the |
StrikerRUS
left a comment
There was a problem hiding this comment.
Thank you very much for digging deep into multiclass objective problems!
I left some last minor comments below.
Co-authored-by: Nikita Titov <nekit94-08@mail.ru>
|
Thanks! @jmoralez do you want a chance to re-review? Since I made some nontrivial changes after your earlier β |
I guess the following warning from timeouted CI job can help us to find a root cause: UPD: created #4948 for this. |
|
This pull request 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. |
Fixes #3934.
This PR proposes changes to add support for the use of custom objective functions with
lightgbm.dask. Nothing functionally needed to change in the package to support this, but this PR makes the following changes:lightgbm.daskWhere did the objective functions added in the tests come from?
Binary classification (logistic regression)
https://github.com/microsoft/LightGBM/blob/af5b40e1f653e25a5f3470e09de4d1c68dc59663/tests/python_package_test/test_sklearn.py#L57
Multiclass classification (multi-logloss)
Converted this code from the R demos to Python. I tested it manually against the R package to confirm that the two functions produce the same results.
https://github.com/microsoft/LightGBM/blob/af5b40e1f653e25a5f3470e09de4d1c68dc59663/R-package/demo/multiclass_custom_objective.R#L45
Ranking and Regression (regression_l2)
https://github.com/microsoft/LightGBM/blob/af5b40e1f653e25a5f3470e09de4d1c68dc59663/tests/python_package_test/test_sklearn.py#L51
I couldn't find an example of a custom objective function for the learning task. This is something that we've received feature requests about in the past (e.g. #1896, #2239, #3381) but none of those discussions produced Python or R code that could be used as a custom objective function for learning-to-rank with LightGBM.
I believe it's fine, for the purposes of these tests, to use the L2 objective for the ranking task. I found that it produced good-enough results (measured by spearman correlation of the predicted scores with the actual labels) that improved as I increased
num_iterations, which I took as a good sign.Why not just add a custom objective function test to
test_{task}?I considered adding something like the following to
test_classifier,test_regressor, andtest_rankerin the Dask tests:@pytest.mark.parametrize('objective', ["regression_l2", _objective_least_squares])That would ensure that custom objective functions are tested for every combination of data type, boosting type, and distributed training strategy.
However, I decided against this because there are already so many Dask tests, and I didn't want to add too much incremental burden to this project's CI. I believe the tests added in this PR provide good enough confidence that the Dask estimators are passing through custom objective functions to the
lightgbm.sklearnequivalents.