Repository navigation
Conversation
Replace `m: Option<usize>` with `m: MaxFeatures` (Sqrt, Fraction, Count, All) in RandomForestClassifier, RandomForestRegressor, ExtraTreesClassifier and ExtraTreesRegressor. `with_m` accepts `impl Into<MaxFeatures>`, so `with_m(3)` still gives `Count(3)`. `fit` returns a ParametersError when `m` is not valid for the data. Breaking change: parameters serialized with an earlier version that contain `m` no longer deserialize. Add tests for the valid and invalid values, called directly and through `fit`.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #531 +/- ##
===========================================
+ Coverage 43.97% 86.99% +43.01%
===========================================
Files 85 100 +15
Lines 7281 9913 +2632
===========================================
+ Hits 3202 8624 +5422
+ Misses 4079 1289 -2790 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
Reviewed at The implementation looks well scoped. Resolving A few improvements before merging:
Overall, the enum and centralized validation are a good improvement. The remaining feedback is primarily regression coverage, migration clarity, and merge hygiene, rather than a request for a broader refactor. |
Fixes #515
Checklist
Current behaviour
The forest estimators (
RandomForestClassifier,RandomForestRegressor,ExtraTreesClassifier,ExtraTreesRegressor) usem: Option<usize>for the number of features to test at each split.Nonegivesfloor(sqrt(p)).Some(0)or a value larger than the number of features is accepted.New expected behaviour
mis now aMaxFeaturesenum, similar tomax_featuresin scikit-learn:Sqrt(default)max(1, floor(sqrt(p)))Fraction(f)max(1, floor(f * p))0 < f <= 1Count(n)n1 <= n <= pAllpwith_macceptsimpl Into<MaxFeatures>, sowith_m(3)still works and givesCount(3).fitreturns aParametersErrorwhen the value is not valid for the data (for exampleCount(0),Count(p + 1),Fraction(1.5)orFraction(NaN)).Sqrt) gives the same number of features as before, so default results do not change.ensemble::max_featureswith docs, a doctest and references.fitreturns an error for each invalid value with both splitters and accepts the boundary values.Change logs
Added
ensemble:MaxFeaturesenum (Sqrt,Fraction,Count,All) sets the number of features to test at each split in the forest estimators.Changed
ensemble:mon the four forest parameter structs is nowMaxFeatures(wasOption<usize>). The search parameters useVec<MaxFeatures>.with_m(3)still works.fitreturns an error whenmis not valid for the data.mno longer deserialize. This release already breaks loading of serialized trees and forests, so we accept this.