实际调参
最优的超参数能为您的数据带来最好的模型。确定调参网格后,您需要在网格的每个点上训练并评估模型,以找出哪一个带来最佳性能。
这可能需要一些时间。因为在使用 k 折交叉验证、集成规模为 n 棵树、调参网格包含 t 个组合的情况下,总共需要训练 k * n * t 个模型。
现在轮到您来进行实际的调参了!已预先加载 customers_train,以及上一个练习的结果 boost_spec 和 tunegrid_boost:
# A tibble: 27 x 3
tree_depth learn_rate sample_size
<int> <dbl> <dbl>
1 1 0.0000000001 0.1
2 8 0.0000000001 0.1
3 15 0.0000000001 0.1
4 1 0.00000316 0.1
...
本练习是课程的一部分
R 中的树模型机器学习
练习说明
- 使用
vfold_cv()为训练数据创建 6 折,并将其保存为folds。 - 使用
tune_grid()基于您的折、调参网格以及roc_auc度量来调参boost_spec。将结果保存为tune_results。 - 绘制结果,用可视化展示调参过程的结果。
交互式实操练习
通过完成这段示例代码来试试这个练习。
# Create CV folds of training data
folds <- ___
# Tune along the grid
tune_results <- ___(___,
still_customer ~ .,
resamples = ___,
grid = ___,
metrics = metric_set(___))
# Plot the results
___(___)