沿网格调优
在创建了调优网格和占位的规范后,您需要在网格的每个点上拟合模型,并评估得到的模型。
在 tidymodels 框架中,这可以通过幻灯片中介绍的 tune_grid() 函数非常轻松地完成。
在接下来的练习中,您将使用信用卡客户数据集,其包含以下列:
still_customer:标记(yes 或 no),指示客户是否仍为活跃客户。total_trans_amt:交易总额(USD)。customer_age:客户年龄。income_category:用于指示年收入类别的标签,如 $60K - $80K 或 Less than $40K。- …以及另外 16 列。
欢迎在控制台中查看 customers tibble!上一个练习的结果 tree_grid 与 tune_spec 仍已加载。
本练习是课程的一部分
R 中的树模型机器学习
练习说明
- 为数据集创建 3 折交叉验证,并保存为
folds。 - 通过在网格上调优规范来创建
tune_results:使用所有自变量预测still_customer,将您的交叉验证折叠作为重采样,并使用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)