0Pricing
R Academy · Lesson

Feature Engineering with recipes

Define preprocessing steps for normalization, encoding, and imputation.

What Is a Recipe?

In tidymodels, a recipe is a blueprint for preprocessing your data. It records the steps needed to transform raw data into model-ready features — without immediately applying them.

The key function is recipe(outcome ~ ., data = train), which defines the formula and the reference dataset used to estimate any statistics needed during preprocessing.

library(recipes)
library(tidymodels)

# Create a recipe using the training data
rec <- recipe(price ~ ., data = train_data)
print(rec)

step_normalize()

step_normalize(all_numeric_predictors()) centers each numeric predictor to mean 0 and scales it to standard deviation 1. This is essential for algorithms sensitive to feature scale, such as logistic regression, SVM, or neural networks.

The mean and SD are computed from the training set and applied consistently to test data via bake().

rec <- recipe(price ~ ., data = train_data) |>
  step_normalize(all_numeric_predictors())

# Check what steps are recorded
print(rec)

All lessons in this course

  1. Feature Engineering with recipes
  2. Model Specifications with parsnip
  3. Workflows: Combining Recipes and Models
  4. Resampling and Cross-Validation with rsample
← Back to R Academy