Skip to content

Commit 0b71cec

Browse files
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

File tree

src/nns/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
"nns_seas": ("nns.seasonality", "nns_seas"),
6666
"nns_sd_cluster": ("nns.stochastic_dominance", "nns_sd_cluster"),
6767
"nns_stack": ("nns.stack", "nns_stack"),
68+
"nns_stack_fit": ("nns.stack", "nns_stack_fit"),
69+
"nns_stack_predict": ("nns.stack", "nns_stack_predict"),
6870
"nns_ss": ("nns.stochastic_superiority", "nns_ss"),
6971
"nns_var": ("nns.var", "nns_var"),
7072
"prepare_factor_predictors": ("nns.regression", "prepare_factor_predictors"),

0 commit comments

Comments
 (0)