-
Notifications
You must be signed in to change notification settings - Fork 4k
[python-package] Added tests on Booster.shuffle_model() #7168
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1098,3 +1098,23 @@ def test_set_field_none_removes_field(rng, field_name): | |||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| d.set_field(field_name, None) | ||||||||||||||||||||||||||||||||||
| assert d.get_field(field_name) is None | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| def test_booster_shuffle_models() -> None: | ||||||||||||||||||||||||||||||||||
| X_train, _, y_train, _ = train_test_split( | ||||||||||||||||||||||||||||||||||
| *load_breast_cancer(return_X_y=True), | ||||||||||||||||||||||||||||||||||
| test_size=0.1, | ||||||||||||||||||||||||||||||||||
| random_state=42, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| train_set = lgb.Dataset(X_train, label=y_train) | ||||||||||||||||||||||||||||||||||
| booster = lgb.Booster( | ||||||||||||||||||||||||||||||||||
| params={"objective": "binary", "verbose": -1}, | ||||||||||||||||||||||||||||||||||
| train_set=train_set, | ||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||
| for _ in range(2): | ||||||||||||||||||||||||||||||||||
| booster.update() | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+1109
to
+1115
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Let's use |
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| model_str_before = booster.model_to_string() | ||||||||||||||||||||||||||||||||||
| booster.shuffle_models(start_iteration=0, end_iteration=-1) | ||||||||||||||||||||||||||||||||||
| model_str_after = booster.model_to_string() | ||||||||||||||||||||||||||||||||||
| assert model_str_before != model_str_after | ||||||||||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is not a very strong test. For example, it'd pass if To do that, you'll have to look a bit deeper into what the function is doing. Start with the docstring: LightGBM/python-package/lightgbm/basic.py Lines 4509 to 4515 in e3d5270
The test should train 10 trees (for example) and:
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The test isn't using the held-out validation data, let's skip the unnecessary train-test splitting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jameslamb sorry for the late response, I will address all your responses on PRs today. Thank you for reviewing!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👋🏻 hey @daguirre11 , will you have some time soon to return to these PRs? I'd be happy to help if you have any questions.
Thanks for all your efforts so far, I really appreciate it!