12.2 Exercise

Write a recipe for the Sale_Price ~ . variables that:

  1. Adds a novel level to all factors
  2. Converts all factors to dummy variables
  3. Catches any zero variance variables
  4. Centers all of the predictors
  5. Scales all of the predictors
  6. Computes the first 5 principal components

Save the result as pca_rec

12.2.1 Solution

pca_rec <-
  recipe(Sale_Price ~ ., data = ames) %>%
  step_novel(all_nominal()) %>%
  step_dummy(all_nominal()) %>%
  step_zv(all_predictors()) %>%
  step_center(all_predictors()) %>%
  step_scale(all_predictors()) %>%
  step_pca(all_predictors(), num_comp = 5)