Extract Arguments from Tidymodel

I have a model m and am trying to extract parameter arguments and put them in a dataframe. The arguments I'd like are in :

m[["fit"]][["fit"]][["spec"]][["args"]]

and are listed as:

$mtry

expr: ^7L
env: empty

$trees

expr: ^1225L
env: empty

$min_n

expr: ^26L
env: empty

$tree_depth

expr: ^5L
env: empty

$learn_rate

expr: ^0.2322614074394
env: empty

$loss_reduction

expr: ^0.61222263464654
env: empty

$sample_size

expr: ^0.813209898024797
env: empty

$stop_iter

expr: ^3L
env: empty

I've tried unlisting, tidy and other helpers which don't work - is there a way to get this information into a tibble or dataframe?

Thanks

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

ok, I usually do this but my issue is with managing the results of a tidy model object (not the process of making the object). If I'm not able to upload the model object I need to figure out how to reprex the object creation.

Thanks for your response.

Hi Michael,

I think you should be able to access them and put in a dataframe by mapping quo_get_expr over it and then just bind_rows:

library(tidyverse)
library(rlang)

m[["fit"]][["fit"]][["spec"]][["args"]] %>% 
  map(rlang::quo_get_expr) %>% 
  bind_rows(.id = "parameter_name")

But hard to verify without a reprex. If I'm incorrect regarding the above code, let me know and I could have a better look at it.

awesome, that works. Thank you for helping me out.

1 Like

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.