Create a high-correlation recipe
Once you have identified highly correlated features, instead of removing them manually, you can use the step_corr()
recipe step in tidymodels
. step_corr()
does not remove all features that are correlated with other features. It attempts to remove as few features as possible. Conceptually, as you saw in the multiple choice exercise, it removes the feature that has the most overlap with any combination of other features. The idea is that the other features contain the same information, so the overlapping information of the removed feature is still represented in those other features.
The tidyverse
and tidymodels
packages have been loaded for you.
This exercise is part of the course
Dimensionality Reduction in R
Exercise instructions
- Create a recipe that uses
step_corr()
with a threshold of 0.7, applying the step to numeric predictors only. - Apply the recipe to
house_sales_df
and store the filtered data infiltered_house_sales_df
. - Use
tidy()
to identify the column or columns that thestep_corr()
filter removed.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# Create a recipe using step_corr to remove numeric predictors correlated > 0.7
corr_recipe <-
___(price ~ ., data = ___) %>%
___(___, ___ = ___) %>%
___(___)
# Apply the recipe to the data
___ <-
___ %>%
___(new_data = ___)
# Identify the features that were removed
___(___, ___ = ___)