準備舞台
你將從 PCA 的角度來探索 attrition_num 資料集,評估是否能在保留多數資訊的同時進行降維。先建立一個 recipe:濾除近乎零變異的特徵、標準化資料,並套用 PCA。
attrition_num 資料集已為你載入。
本練習屬於課程
R 的特徵工程
練習說明
- 移除可能的近乎零變異特徵。
- 標準化所有數值型資料。
- 套用 PCA。
- 準備(prepare)該 recipe 後,存取輸出元素的名稱。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
pc_recipe <- recipe(~., data = attrition_num) %>%
# Remove possible near-zero variance features
___(all_numeric()) %>%
# Normalize all numeric data
___(___()) %>%
# Apply PCA
___(all_numeric())
# Access the names of the output elements by preparing the recipe
pca_output <- ___(___)
names(pca_output)