開始使用免費開始

基本 recipe

使用包含所有員工數值資料的 attrition_num 資料集(這些員工已離職),你想建立一個模型來預測員工是否可能留下,目標變數是 Attrition,為以 factor 編碼的二元變數。先從定義一個「不做任何轉換」的基本 recipe 開始,只需指定模型公式與訓練資料。

已為你載入 attrition_num 資料、羅吉斯迴歸 lr_model、使用者自訂的 class-evaluate() 函式,以及 traintest 切分。

本練習屬於課程

R 的特徵工程

檢視課程

練習說明

  • 建立一個僅定義模型公式的基本 recipe。

動手互動練習

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

# Create a plain recipe defining only the model formula
lr_recipe_plain <- 
  ___(___ ~., ___ = ___)

lr_workflow_plain <- workflow() %>%
  add_model(lr_model) %>%
  add_recipe(lr_recipe_plain)
lr_fit_plain <- lr_workflow_plain %>%
  fit(train)
lr_aug_plain <-
  lr_fit_plain %>% augment(test)
lr_aug_plain %>% class_evaluate(truth = Attrition,
                 estimate = .pred_class,.pred_No)
編輯並執行程式碼