tidymodels framework is a collection of R packages for modeling and machine learning using tidyverse principles. Earlier this year, we
started regular updates here on the tidyverse blog summarizing recent developments in the tidymodels ecosystem. You can check out the
tidymodels tag to find all tidymodels blog posts here, including those that focus on a single package or more major releases. The purpose of these roundup posts is to keep you informed about any releases you may have missed and useful new functionality as we maintain these packages.
Recently, we had a series of CRAN releases: hardhat, workflows, parsnip, tune, finetune, workflowsets, and discrim. These were coordinated because of some cross-package improvements. This blog post summarizes the changes.
The tidymodels team decided that we needed a consistent set of APIs for extracting things from objects. For example, a parsnip model contains the underlying model fit based on the engine. A
linear_reg() model with the
"lm" engine contains an
lm object. There were some existing functions to do this (mostly named
pull_*()) but they were fairly inconsistent and were not generics.
We added the following functions:
The nice thing about this change is that a function such as
extract_recipe() can be used with objects created by the tune, workflows, or workflowsets packages.
pull_*() methods have been soft-deprecated and will stick around for a while.
One issue that we’ve seen in the parsnip documentation is that there is just so much on each model page. It can be intimidating and difficult to find that one piece of information that you were looking for.
We’ve reorganized the model pages so that there are now sub-packages for each engine. For example, when you use
?linear_reg, the help page has a dynamic list of engines from parsnip or any parsnip-adjacent package that has been loaded. Here is what the
pkgdown site looks like:
There is a similar dynamic list in the
See Also section.
Each engine page provides basic information about tuning parameters, modes, preprocessing requirements, and anything else that we thing is relevant. For example, for the C5.0 engine for
Finally, the existing parsnip documentation didn’t show the actual fitting and/or prediction in action. A new pkgdown article has worked examples demonstrating the use of parsnip models on real data. Here is a screen shot for MARS regression via the earth package:
We think that these changes will greatly improve the whole parsnip experience, especially for new users.
First, we enabled a default engine for parsnip models (you may have noticed this in the screen shots above). This produces simpler code for some model functions and, if a model has a single mode, fitting is as concise as
# use lm() for regression linear_reg() %>% fit(mpg ~ ., data = mtcars)
Another nice feature is more succinct piping for workflows. A preprocessor, such as a formula or recipe, can be piped into
workflow() now. Also, there is an optional second argument in that function for the model specification.
car_rec <- recipe(mpg ~ ., data = mtcars) %>% step_ns(disp, deg_free = 5) car_wflow <- workflow() %>% add_recipe(car_rec) %>% add_model(linear_reg())
you can now use
car_wflow <- recipe(mpg ~ ., data = mtcars) %>% step_ns(disp, deg_free = 5) %>% workflow(linear_reg())
If you might be on the fence about using tidymodels, David’s blog post does an excellent job encapsulating the benefits of our approach, so give it a read.
parsnip now has a generalized additive model function
gen_additive_mod()! There is currently one engine (
The tune package has better control over random numbers since, in some cases, the RNGkind was changed after tuning a model.
The discrim package has the new parsnip-like documentation and new model engines. Also, the shrunken discriminant analysis method of Ahdesmaki and Strimmer (2010) was added as an engine to
discrim_linear(). The newly resurrected sparsediscrim package allowed use to include new engines for
We’d like to thank everyone who has contributed to these packages since their last release: