Use weighted min_bin_size and max_bin_size when sample_weight provided#359
Merged
guillermo-navas-palencia merged 4 commits intoJun 4, 2025
Conversation
…ameters when sample_weight provided
Owner
|
Great PR. Thanks a lot for your contribution. Regarding the clarification about the min/max_bin_size, if think it is a good idea. |
guillermo-navas-palencia
approved these changes
Jun 4, 2025
guillermo-navas-palencia
approved these changes
Jun 4, 2025
10dd47a
into
guillermo-navas-palencia:develop
12 checks passed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix #323
Hi Guillermo,
Thanks for developing this amazing tool. I found it extremely useful and easy to use. I hope this PR resolves an existing issue with sample_weight.
Added a property
self._n_samples_weightedto calculate weighted sample size - ifsample_weightis provided it will be the weighted sample size (sum(sample_weight), if not, if will be the same asself._n_samples.self._n_samples_weightedis used when calculating themin_bin_sizeandmax_bin_sizein_fit_optimizer().When
sample_weightis provided, usemin_weight_fraction_leafinstead ofmin_samples_leaffor DecisionTreeClassifier. It was suggested in the sklearn documentation:I used the test code in #323 to test the fix:
Before:

After:

Todo
min_bin_sizeandmax_bin_sizeinclude the mix of missing and special groups. I can add that if you think the change makes sense.Thanks again for creating and maintaining this tool!