feat: add linfa-residual-sequence crate#430
feat: add linfa-residual-sequence crate#430Feiyang472 wants to merge 19 commits intorust-ml:masterfrom
Conversation
Implements ResidualSequence Struct and StackWith trait for composing regression models in a boosting / residual-stacking pattern. The second (and any further) model trains on the residuals left by the previous one; predictions are summed. Docs and tests were written with AI assistance.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #430 +/- ##
=======================================
Coverage 76.76% 76.76%
=======================================
Files 105 106 +1
Lines 7359 7411 +52
=======================================
+ Hits 5649 5689 +40
- Misses 1710 1722 +12 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Hi! It looks like a nice addition! I think you should move it in the |
|
Hi @relf, absolutely composing is the better place for this to be! I have moved it to composing/residual-sequence. |
relf
left a comment
There was a problem hiding this comment.
Ok, I think you should take a look at the contribution guidelines. Specially the sections about the implementation of PredictInplace trait and the optional serde support. As there is no hyperparameters (at the moment?), I guess you can skip the ParamGuard pattern.
Implement Shrinkage implement paramguard for shrinkage
| where | ||
| Self: Fit<Array2<F>, Array1<F>, E>, | ||
| E: std::error::Error + From<crate::error::Error>; | ||
| } |
There was a problem hiding this comment.
could also add another method which just shrinks by F::one() (no shrinking). not sure how to name it
There was a problem hiding this comment.
Well, the .shrink_by(1.0) is noisy... With a conversion we could have:
let model = MeanParams.stack_with(MeanParams.into()));otherwise you can add another method:
let model = MeanParams.stack_with_full(MeanParams);It is better if the most common use case has the shorter name.
We could also have just stack(MeanParams) and stack_shrunk(MeanParams, 0.5).
There was a problem hiding this comment.
Hi @relf thanks for reviewing. I propose the two methods:
chain(corrector: C)
chain_shrunk(corrector: Shrunk<C, F>)
I went with chain over stack since "stack" is so strongly associated with the fundamental data structure that it could be confusing in a library context. chain also echoes the ResidualChain struct name you suggested.
I kept chain_shrunk accepting a pre-wrapped Shrunk<C, F> rather than an inline shrinkage value (as in chain_shrunk(corrector, 0.5)) so that a Shrunk corrector can be constructed once and reused across multiple pipelines.
rename stack_with -> chain_shrunk
Hi! Wanted to float the idea of a small crate for chaining models together additively, fitting each model with the residuals of the previous one, like below
feels like a natural ergonomic addition which could sit as a crate in linfa.
Happy to hear if this belongs somewhere else (folded into an existing crate, or not at all).