開始使用免費開始

建立高相關性的 recipe

當你找出高度相關的特徵後,與其手動移除它們,你可以在 tidymodels 中使用 step_corr() 這個 recipe 步驟。step_corr() 不會把所有彼此相關的特徵全部移除,它會嘗試移除最少量的特徵。概念上,如同你在單選題中所見,它會移除與其他特徵任意組合之間重疊最多的那個特徵。這樣做的想法是,其他特徵已包含相同的資訊,因此被移除特徵所重疊的資訊,仍然能在那些其他特徵中被表達出來。

tidyversetidymodels 套件已為你載入。

本練習屬於課程

R 的降維

檢視課程

練習說明

  • 建立一個使用 step_corr()、門檻為 0.7 的 recipe,且只套用在數值型預測變數上。
  • 將這個 recipe 套用到 house_sales_df,並把篩選後的資料存成 filtered_house_sales_df
  • 使用 tidy() 找出被 step_corr() 篩選器移除的欄位(或多個欄位)。

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# 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
___(___, ___ = ___)
編輯並執行程式碼