Repository navigation
Match sklearn sample weights - #478
Merged
Merged
Conversation
Match the behavior for sklearn on sample weights. - when bootstrap is true, sample weights are only used during the bootstrap phase - when bootstrap is false, then sample weights are passed down to individual trees. Added tests for this: Compare RandomForestRegressor and ExtraTreesRegressor predictions (train, probe, OOB) with reference values from sklearn 1.9.1. Each reference value is the mean of 10 sklearn runs. smartcore and numpy use different RNGs, so the tests use a tolerance of about 4 x the standard deviation of one sklearn run. For RandomForestRegressor: cover max_features = all and 2, with and without sample weights. For ExtraTreesRegressor: cover max_features = all, with and without sample weights.
Collaborator
|
Thanks for the fix and the thorough parity tests. Review notes (based on the diff and CI results; some points are things to verify rather than confirmed defects): Correctness
CI
Tests
|
Collaborator
|
please check the failure in |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #478 +/- ##
===========================================
+ Coverage 43.97% 63.63% +19.65%
===========================================
Files 85 96 +11
Lines 7281 8522 +1241
===========================================
+ Hits 3202 5423 +2221
+ Misses 4079 3099 -980 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Mec-iS
approved these changes
Oct 5, 2026
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.
Fixes #477
Checklist
Current behaviour
At the moment, smartcore uses the sample weights twice:
New expected behaviour
Sample weights in the same way as in sklearn, i.e. during bootstrapping OR during the fitting of the tree
Change logs
In base_forest_regressor the sample weights are passed as None when bootstrapping is used, otherwise the sample weights are passed in as is.
Nothing in the public API changed.
Added
Additional tests to try to verify that the implementation matches sklearn's behavior
in extra_trees_regressor and random_forest_regressor.