CommencerCommencer gratuitement

Box-Cox transformation

Using the attrition_num dataset with all numerical data about employees who have left the company, you want to build a model that can predict if an employee is likely to stay, using Attrition, a binary variable coded as a factor. To get the features to behave nearly normally, you will create a recipe that implements the Box-Cox transformation.

The attrition_numdata, the logistic regression lr_model, the user-defined class-evaluate() function, and the trainand test splits are loaded for you.

Cet exercice fait partie du cours

Feature Engineering in R

Afficher le cours

Instructions

  • Create a recipe that uses Box-Cox to transform all numeric features, including the target.

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Create a recipe that uses Box-Cox to transform all numeric features
lr_recipe_BC <- 
  recipe(Attrition ~., data = train) %>%
  ___(___)

lr_workflow_BC <- workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_BC)
lr_fit_BC <- lr_workflow_BC %>%
  fit(train)
lr_aug_BC <-
  lr_fit_BC %>% augment(test)
lr_aug_BC %>% class_evaluate(truth = Attrition,
                 estimate = .pred_class,.pred_No)
Modifier et exécuter le code