Skip to content

Add orbital.model_stack() for stacks::stacks() ensembles - #191

Merged
EmilHvitfeldt merged 6 commits into
mainfrom
add-stacks-support
Sep 30, 2026
Merged

EmilHvitfeldt merged 6 commits into
mainfrom
add-stacks-support

Conversation

@EmilHvitfeldt

Copy link
Copy Markdown
Member

orbital() now supports fitted stacks::stacks() ensembles. A stack's blending model is already an ordinary parsnip glmnet fit, so this reuses each member workflow's own orbital() equations, renames their outputs to match what the blend model expects as predictors, and splices the two together. Closes #54.

Referencing `norm` unquoted still evaluated correctly on its own, but
made every occurrence of that column name text-identical across
expressions, which blocks any caller that needs to rename these
equations' columns by substituting backtick-quoted references (as
orbital.model_stack() needs to do for multiclass ensemble members).
A fitted model_stack's blending model (x$coefs) is already an
ordinary parsnip model_fit wrapping a glmnet fit, so orbital(x$coefs)
works unmodified; its preproc term labels are exactly the member
prediction column names it expects as predictors. This method builds
each member workflow's own equations, renames their outputs (and any
internal cross-references between them) to match those expected
column names, and splices the result with the blend model's own
equations.
rename_stack_member_eqs() relocated cross-references between a member's
own equations by gsub-ing for backtick-quoted names. That matches
orbital's hand-written glue templates, which always backtick their
references, but not tidypredict-generated expressions such as
separate_trees_eqs()'s tree-averaging formula, which only backticks a
name when it isn't already a syntactically valid identifier (e.g.
`.pred_tree_1` comes out bare). The gsub silently missed those bare
references, so orbital(stack, separate_trees = TRUE) produced
equations that referenced columns which no longer existed under their
renamed member-suffixed names.

Switch to substituting at the parsed-expression level instead, which
works regardless of whether the reference happens to be
backtick-quoted, and as a side effect no longer needs the longest-name-
first ordering that guarded against substring collisions.
Cover paths the original test suite left untested: a type/mode
mismatch, prefix forwarding to just the blend model's output,
separate_trees propagating into a tree-based member, a member's build
failure being wrapped with its name, the member name-collision guard,
check_fitted_stack()'s other failure branches, rename_stack_member_eqs()
directly (including the norm/norm2 substring-safety case its own
comment calls out), type = "class"/"prob" requested alone, and a stack
with three distinct member model types.
@EmilHvitfeldt
EmilHvitfeldt merged commit 3b0a164 into main Sep 30, 2026
14 of 21 checks passed
@EmilHvitfeldt
EmilHvitfeldt deleted the add-stacks-support branch September 30, 2026 21:04
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.

Add support for {stacks} models

1 participant