Machine learning with tidymodels :: Cheatsheet
Intro
tidymodels is a collection of R packages for modeling and machine learning that share a common design and grammar. Unlike most cheatsheets, which cover the functions of a single package, this cheatsheet maps the packages themselves, grouping each by where it fits in the machine learning workflow.
The machine learning workflow
Resampling
Split and resample data for honest evaluation.
Pre-processing
Prepare data for modeling.
recipesThe preprocessing framework for building pipeable feature-engineering steps.
embedRecipe steps that encode categorical predictors via target, likelihood, and entity embeddings.
textrecipesRecipe steps that turn text into model-ready features.
themisRecipe steps to rebalance class-imbalanced data with up-sampling, down-sampling, and SMOTE.
filtroFilter-based supervised feature selection.
Modeling
Define and fit models through one consistent interface.
Classification & regression
Specialized problems
poissonregPoisson and count-data regression.
censoredSurvival models for time-to-event outcomes.
multilevelmodMixed-effects and hierarchical models.
tidyclustClustering models under a tidy interface.
plsmodPartial least squares and other projection models.
tabbyTabular deep-learning models; runs with brulee and tabpfn.
aguaInterface to h2o models and AutoML.
Post-processing
Adjust predictions.
Measuring
Measure model quality.
Orchestrating
Tie the pieces together.
Tuning
Optimize hyperparameters.
Deploy
Put models into production.
Prepare & serve
Run in a database
Data
Datasets used in documentation, tests, and teaching.
Deep learning
R packages that implement or wrap tabular deep-learning models.
Other
General
Development
The tidymodels package

The tidymodels package installs and loads a set of packages that are considered important during day-to-day machine learning development.
It loads the following packages from tidymodels:
rsamplerecipesparsnipyardsticktailortunedialsworkflowsworkflowsetsbroominfermodeldata
It also loads the following packages from the tidyverse:
dplyrggplot2purrrtidyr
Example
A complete workflow: split, engineer features, tune, finalize, and deploy.
library(tidymodels)
# Split data and make CV folds
set.seed(857)
splits <- ames |>
initial_split(prop = 0.8)
train <- training(splits)
folds <- train |>
vfold_cv(v = 5)
# Feature engineering in a recipe
rec <- recipe(
Sale_Price ~ Gr_Liv_Area + Year_Built + Bldg_Type,
data = train
) |>
step_log(Gr_Liv_Area, base = 10) |>
step_dummy(all_nominal_predictors()) |>
step_normalize(all_numeric_predictors())
# Model with parameters to tune
mod <- decision_tree(
cost_complexity = tune(),
tree_depth = tune()
) |>
set_engine("rpart") |>
set_mode("regression")
# Bundle into a workflow
wf <- workflow() |>
add_recipe(rec) |>
add_model(mod)
# Tune over the folds
res <- wf |>
tune_grid(
resamples = folds,
grid = 10
)
# Finalize best, refit, test once
best <- res |>
select_best(metric = "rmse")
final <- wf |>
finalize_workflow(best) |>
last_fit(splits)
collect_metrics(final)# A tibble: 2 × 4
.metric .estimator .estimate .config
<chr> <chr> <dbl> <chr>
1 rmse standard 41683. pre0_mod0_post0
2 rsq standard 0.731 pre0_mod0_post0
# Deploy the fitted workflow
library(vetiver)
library(pins)
v <- final |>
extract_workflow() |>
vetiver_model("ames_tree")
board <- board_temp()
vetiver_pin_write(board, v)



























