Sure, you can get this pretty easily. Once the stack is blended, there is an equation
sub-object that has the generalized linear model prediction equation.
Here's a regression example from the docs:
library(tidymodels)
library(stacks)
library(rlang)
#>
#> Attaching package: 'rlang'
#> The following objects are masked from 'package:purrr':
#>
#> %@%, flatten, flatten_chr, flatten_dbl, flatten_int, flatten_lgl,
#> flatten_raw, invoke, splice
tidymodels_prefer()
# from ?blend_predictions
reg_st <-
stacks() %>%
add_candidates(reg_res_lr) %>%
add_candidates(reg_res_svm) %>%
add_candidates(reg_res_sp)
# evaluate the data stack
reg_st <-
reg_st %>%
blend_predictions()
reg_st$equations
#> $numeric
#> $.pred
#> -8.84601130389494 + (reg_res_svm_1_3 * 0.63844261429) + (reg_res_sp_10_1 *
#> 0.0481870055572203) + (reg_res_sp_03_1 * 0.485948459397137)
#>
#> attr(,"class")
#> [1] "elnet_numeric"
# An R expression:
reg_st$equations$numeric$.pred
#> -8.84601130389494 + (reg_res_svm_1_3 * 0.63844261429) + (reg_res_sp_10_1 *
#> 0.0481870055572203) + (reg_res_sp_03_1 * 0.485948459397137)
# Make into text:
expr_deparse(reg_st$equations$numeric$.pred, width = 200)
#> [1] "-8.84601130389494 + (reg_res_svm_1_3 * 0.63844261429) + (reg_res_sp_10_1 * 0.0481870055572203) + (reg_res_sp_03_1 * 0.485948459397137)"
Created on 2023-09-16 with reprex v2.0.2