Give each tree its own seed in random forest regressor/classifier - #475
Merged
Merged
Conversation
…est classifier. Before this change, every tree of the forest used the same seed. Thus all trees picked the same feature samples. Now each tree uses seed + tree index resulting in different features being chosen. Add a test that checks that the trees split on different features.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #475 +/- ##
===========================================
+ Coverage 43.97% 63.75% +19.77%
===========================================
Files 85 96 +11
Lines 7281 8498 +1217
===========================================
+ Hits 3202 5418 +2216
+ Misses 4079 3080 -999 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
|
Consider a small test showing that fitting twice with the same seed gives identical forests. That locks in reproducibility, which is the main promise of this change. |
Add a test to check that the output of the random forest regressor is deterministic given a certain seed.
Contributor
Author
|
Test added in 46651cc |
Mec-iS
approved these changes
Oct 3, 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 #474
Checklist
Current behaviour
In
RandomForestClassifierandBaseForestRegressor, every tree gets the same seed (parameters.seed). Thus all trees use the same random feature samples (and the same random thresholds withSplitter::Random). Withbootstrap: false, all trees in the regressor are the same.New expected behaviour
Each tree gets its own fixed seed:
parameters.seed + tree index. The trees use different feature samples, and the results are still reproducible for a given seed.Change logs
Changed
RandomForestClassifierandBaseForestRegressor(and through itRandomForestRegressorandExtraTreesRegressor): give each tree its own seed.Added
each_tree_gets_different_feature_sampletests forBaseForestRegressorandRandomForestClassifier.