開始使用免費開始

擬合最佳模型

lasso_grid 包含 50 組不同的模型規格,對應 penalty_grid 中的 50 個不同 penalty 值。這個練習中,你將找出並擬合具有最佳 penalty 值的模型。完成後,你會得到一個能最佳化特徵選擇、以提升模型效能的 lasso 迴歸模型。

已為你提供 lasso_workflowtrain 可供使用。tidyversetidymodels 套件也已載入。

本練習屬於課程

R 的降維

檢視課程

練習說明

  • 依據 RMSE 取回表現最佳的已擬合模型。
  • 使用 finalize_workflow() 依照 best_rmse 來擬合模型。
  • 顯示 final_lasso 的模型係數。

動手互動練習

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

# Retrieve the best RMSE
best_rmse <- ___ %>% 
  ___("___")

# Refit the model with the best RMSE
final_lasso <- 
  ___(___, ___) %>% 
  fit(train)

# Display the non-zero model coefficients
tidy(___) %>% 
  filter(___ > ___)
編輯並執行程式碼