Saving a model fit with tidymodels

Hi all, I have what I think should be an easy question. I am hoping to teach my students how to save models that were fit using tidymodels to use later. For example, they might use a model in a Shiny app. I think of this as a mini "put the model into production" exercise. Right now, I show them how to do this using saveRDS(), but it seems like that's a bad idea since it sucks a lot of memory. From this tidypredict info, it seems I should be using parse_model() and write_yml() instead? Maybe combined with something from butcher to make the file smaller? Can anyone direct me to an example where this is done? Thanks so much!

This is a little out of date now, but you can check out the very end of this example training script for an example approach.

Some things I would do definitely as of today:

  • Use extract_workflow() to get the trained workflow out of the last_fit() object.
  • (Optional) Use butcher on the workflow for models that aren't already as streamlined as the one used for the demonstration.
  • Probably use readr::write_rds() because I like the defaults better.

Thanks! This should be a great start for what I need for my class.

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.