Commit 0b71cec
committed
stack: add nns_stack_fit / nns_stack_predict (fit-once, reuse RPM/CV)
Adds a real fit/predict split to NNS.stack so the cross-validated model
selection - the dominant cost - runs once and is reused across predictions,
instead of re-running the full out-of-fold CV on every call.
* nns_stack gains an opt-in "fitted" bypass: when supplied, the three CV
fold-loops (dimension count, n.best, ensemble weight) are skipped and the
stored hyperparameters are used; only the (cheap, test-dependent) final
production fit + projection runs. The default (fitted=None) leaves behavior
byte-identical.
* return_fit=True attaches the selected hyperparameters as the "_fit" state;
the default public result dict is unchanged (no new key).
* nns_stack_fit(x, y, ...) runs the selection once and returns a fit object;
nns_stack_predict(fit, newdata) scores new data reusing it.
Verified: nns_stack_predict(fit, newdata) is byte-identical to a full
nns_stack(x, y, newdata) call across method in {(1,2),(1,),(2,)} times
dim_red_method in {cor, equal, NNS.dep} (the selection is test-independent).
Fit-once + 5 predictions runs ~5.4x faster than 5 full stacks (2000x4,
order='max', folds=5). Full invariant suite (346) passes unchanged.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>1 parent feee35c commit 0b71cec
3 files changed
Lines changed: 311 additions & 193 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
65 | 65 | | |
66 | 66 | | |
67 | 67 | | |
| 68 | + | |
| 69 | + | |
68 | 70 | | |
69 | 71 | | |
70 | 72 | | |
| |||
0 commit comments