Skip to content

Fix RandomForest ignoring the max_depth hyperparameter#409

Merged
JudithBernett merged 1 commit into
daisybio:developmentfrom
jfrog64:fix/random-forest-max-depth
May 29, 2026
Merged

Fix RandomForest ignoring the max_depth hyperparameter#409
JudithBernett merged 1 commit into
daisybio:developmentfrom
jfrog64:fix/random-forest-max-depth

Conversation

@jfrog64
Copy link
Copy Markdown

@jfrog64 jfrog64 commented May 29, 2026

Problem

RandomForest.build_model reads max_depth from the hyperparameters (and even
performs the "None"None conversion), but never passes it to the
RandomForestRegressor constructor. As a result every forest is built with
sklearn's default max_depth=None (unlimited depth), regardless of the value
configured in hyperparameters.yaml, and hyperparameter tuning over max_depth
is a no-op (all candidate values produce identical models).

This also affects SingleDrugRandomForest and MultiViewRandomForest, since both
inherit build_model from RandomForest.

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_depth to the RandomForestRegressor constructor.

Test

Added test_random_forest_respects_max_depth (parametrized over 5 / 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.

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>
Copy link
Copy Markdown
Collaborator

@PascalIversen PascalIversen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good! nice catch! Thanks!!!

@codecov-commenter
Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.
⚠️ Please upload report for BASE (development@fd1aeee). Learn more about missing BASE report.
❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@JudithBernett JudithBernett merged commit 953224d into daisybio:development May 29, 2026
16 checks passed
@jfrog64
Copy link
Copy Markdown
Author

jfrog64 commented May 29, 2026

Thanks!

@jfrog64 jfrog64 deleted the fix/random-forest-max-depth branch May 29, 2026 17:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants