開始使用免費開始

沿著網格調參

建立調參網格與 dummy 規格之後,你需要在每個網格點訓練模型,並評估得到的模型。 在 tidymodels 架構下,使用投影片介紹過的 tune_grid() 就能非常輕鬆地完成。

在接下來的練習中,你會使用「信用卡客戶資料集」,其中包含以下欄位:

  • still_customer:標記(yes 或 no),指出客戶是否仍為活躍客戶
  • total_trans_amt:交易總金額(單位:USD)
  • customer_age:客戶年齡
  • income_category:以 $60K - $80KLess than $40K 這類標籤表示年度收入區間
  • ……以及另外 16 個欄位。

你可以在主控台檢視 customers tibble!前一題的結果 tree_gridtune_spec 仍已載入。

本練習屬於課程

R 的樹狀模型機器學習

檢視課程

練習說明

  • 對資料集建立 3 個交叉驗證摺疊,並將結果存為 folds
  • 建立 tune_results:沿著網格對規格進行調參,使用所有預測變數來預測 still_customer,以你的 CV 摺疊作為重抽樣,並使用 metric_set(accuracy)
  • 使用 autoplot() 繪製調參結果。

動手互動練習

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

set.seed(275)

# Create CV folds of the customers tibble
folds <- ___

# Tune along the grid
tune_results <- tune_grid(___, 
                          ___,
                          resamples = ___,
                          grid = ___,
                          metrics = ___)

# Plot the tuning results
___(tune_results)
編輯並執行程式碼