拟合最佳模型
lasso_grid 在 penalty_grid 中包含 50 个具有不同 penalty 值的模型规格。在本练习中,您将找到并拟合具有最优 penalty 值的模型。这样,您将得到一个能够优化特征选择、以获得最佳模型性能的 lasso 回归模型。
lasso_workflow 和 train 可供您使用。tidyverse 和 tidymodels 包也已为您加载。
本练习是课程的一部分
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(___ > ___)