Fix RandomForest ignoring the max_depth hyperparameter#409
Merged
JudithBernett merged 1 commit intoMay 29, 2026
Merged
Conversation
RandomForest.build_model read max_depth from the hyperparameters (including the "None" -> None conversion) but never passed it to the RandomForestRegressor constructor. As a result every forest was built with sklearn's default max_depth=None regardless of the configured value, and hyperparameter tuning over max_depth had no effect. This also affects SingleDrugRandomForest and MultiViewRandomForest, which inherit build_model. Add a regression test asserting max_depth is forwarded to the underlying RandomForestRegressor. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
PascalIversen
approved these changes
May 29, 2026
Collaborator
PascalIversen
left a comment
There was a problem hiding this comment.
looks good! nice catch! Thanks!!!
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## development #409 +/- ##
==============================================
Coverage ? 81.91%
==============================================
Files ? 67
Lines ? 7243
Branches ? 0
==============================================
Hits ? 5933
Misses ? 1310
Partials ? 0 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Author
|
Thanks! |
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.
Problem
RandomForest.build_modelreadsmax_depthfrom the hyperparameters (and evenperforms the
"None"→Noneconversion), but never passes it to theRandomForestRegressorconstructor. As a result every forest is built withsklearn's default
max_depth=None(unlimited depth), regardless of the valueconfigured in
hyperparameters.yaml, and hyperparameter tuning overmax_depthis a no-op (all candidate values produce identical models).
This also affects
SingleDrugRandomForestandMultiViewRandomForest, since bothinherit
build_modelfromRandomForest.Note: the existing model tests already set
max_depth = 2 # reduce test time,which never actually took effect because of this bug.
Fix
Pass
max_depthto theRandomForestRegressorconstructor.Test
Added
test_random_forest_respects_max_depth(parametrized over5 / 10 / 30 / None)asserting the value is forwarded to the underlying sklearn model.
Locally verified:
pre-commit,mypy, and the RandomForest / MultiViewRandomForest /SingleDrugRandomForest model tests all pass.