篩選變數重要度
attrition 資料集包含 839 筆觀測與 30 個用來預測「Attrition」的自變數。你想要比較兩種模型效能的取捨:一種使用所有可用自變數,另一種是只用少數資訊量高變數的精簡模型。
在這個練習中,你會先擬合一個模型,並檢視該模型的變數重要度。接下來的練習,你會用這個模型與一個精簡模型比較效能。
環境中已提供 train 與 test 的切分、vip() 套件,還有預先宣告的羅吉斯迴歸 model。
本練習屬於課程
R 的特徵工程
練習說明
- 建立一個使用所有自變數來預測
Attrition的 recipe。 - 將 workflow 擬合在訓練資料上。
- 使用
fit_full物件繪製模型的變數重要度。 - 在呼叫
vip()之前套用extract_fit_parsnip(),以提供所需的資訊。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Create a recipe that models Attrition using all the predictors
recipe_full <- ___(___, data = train)
workflow_full <- workflow() %>%
add_model(model) %>%
add_recipe(recipe_full)
# Fit the workflow to the training data
fit_full <- ___ %>%
___(data = train)
# Use the fit_full object to graph the variable importance of your model. Apply extract_fit_parsnip() function before vip()
fit_full %>% ___() %>%
___(aesthetics = list(fill = "steelblue"))