Why can't use normal fit() with library(stacks) ? and how to extract_model from model_stack?

library(stacks) can only add fit_resample() or tune_*().
Why do candidates only receive the results of resample+fit?

Can't it also receive workflow classes created with normal fit()?

In addition, is it possible to extract only the members with coefficients as individual models from the model_stack that is the result of fit_members()?

thank you

Stacking is a specific method that uses out-of-sample predictions to create the ensemble. fit() does not generate those so it wouldn't be appropriate to use.

1 Like

Thank you.

Are there any plans to make it available in the future?

And do you know how to get a specific model out of stacks()object?

Make what available?

Do you mean the glmnet model that defines the ensemble or the individual models?

1 Like

Thank you for your comment.

Make what available?

The question is
"Are there any plans to allow add_candidate() to handle the results of fit()?"

Do you mean the glmnet model that defines the ensemble or the individual models?

I mean each and every model.
For example, the models with non-zero coefficients can be extracted separately.
I wanted to know if it will be possible to extract from the models in stacks as in extract_*().

thank you

No, because the results don't have the information needed to fit the stack.

Sure. Here is some code:

#> Registered S3 method overwritten by 'tune':
#>   method                   from   
#>   required_pkgs.model_spec parsnip

reg_st <- 
  stacks() %>%
  add_candidates(reg_res_lr) %>%
  add_candidates(reg_res_svm) %>%
  add_candidates(reg_res_sp) %>% 
  blend_predictions() %>%   # <- defines what is in the ensemble
  fit_members()             # <- creates all of the model fits

#> ── A stacked ensemble model ─────────────────────────────────────
#> Out of 15 possible candidate members, the ensemble retained 4.
#> Penalty: 0.1.
#> Mixture: 1.
#> The 4 highest weighted members are:
#> # A tibble: 4 × 3
#>   member          type       weight
#>   <chr>           <chr>       <dbl>
#> 1 reg_res_svm_1_5 svm_rbf     2.64 
#> 2 reg_res_svm_1_3 svm_rbf     0.675
#> 3 reg_res_svm_1_1 svm_rbf     0.302
#> 4 reg_res_sp_2_1  linear_reg  0.236

#> [1] 4

model_objects <- 
  # models are in member_fits
  reg_st$member_fits %>% 
  # pull out the underlying fit objects

map_chr(model_objects, ~ class(.x)[1])
#> reg_res_svm_1_5 reg_res_svm_1_3 reg_res_svm_1_1  reg_res_sp_2_1 
#>          "ksvm"          "ksvm"          "ksvm"            "lm"

Created on 2021-10-29 by the reprex package (v2.0.0)


I was able to retrieve the model.
Thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.