自訂調參網格

使用 R 的 caret 進行 Machine Learning

Zach Mayer

Data Scientist at DataRobot and co-author of caret

自訂調參的優缺點

  • 將自訂調參網格傳入 tuneGrid 參數
  • 優點
    • 擬合 caret 模型最有彈性的方式
    • 完全掌控模型如何擬合
  • 缺點
    • 需要一定的模型知識
    • 可能大幅增加執行時間
使用 R 的 caret 進行 Machine Learning

自訂調參範例

# Define a custom tuning grid
myGrid <- data.frame(mtry = c(2, 3, 4, 5, 10, 20))
# Fit a model with a custom tuning grid
set.seed(42)
model <- train(
  Class ~ ., 
  data = Sonar, 
  method = "ranger",            
  tuneGrid = myGrid
)
# Plot the results
plot(model)
使用 R 的 caret 進行 Machine Learning

自訂調參

影像顯示「準確率」對「隨機選取的預測變數」的折線圖,於 x = 10 達到峰值。

使用 R 的 caret 進行 Machine Learning

一起來練習吧!

使用 R 的 caret 進行 Machine Learning

Preparing Video For Download...