使用 Lasso 的手動正規化
attrition 資料集包含 30 個變數。人資部門要你建立一個容易解讀與維護的模型。他們特別希望減少特徵數量,讓模型盡可能好理解。
在這個練習中,你會用 Lasso 自動減少模型中的變數數量。第一次嘗試中,你會手動輸入一個懲罰係數,並觀察模型的行為。
train 和 test 資料,以及基本的 recipe 都已為你載入。
本練習屬於課程
R 的特徵工程
練習說明
- 將你的邏輯斯回歸模型設為使用
glmnet引擎。 - 設定引數,以懲罰係數 0.06 執行 Lasso。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
model_lasso_manual <- logistic_reg() %>%
# Set the glmnet engine for your logistic regression model
___(___) %>%
# Set arguments to run Lasso with a penalty of 0.06
set_args(mixture = ___, ___ = ___)
workflow_lasso_manual <- workflow() %>%
add_model(model_lasso_manual) %>%
add_recipe(recipe)
fit_lasso_manual <- workflow_lasso_manual %>%
fit(train)
tidy(fit_lasso_manual)