交叉验证数据框
现在您已经留出一部分数据作为 testing data,可以用其余数据来寻找表现最好的模型。
在本练习中,您将使用 rsample 包中的 vfold_cv() 函数,把训练数据拆分为 5 组 train-validate 集合。
本练习是课程的一部分
Tidyverse 中的机器学习
练习说明
- 使用
vfold_cv()基于training_data构建一个用于 5 折交叉验证的数据框,并将其赋值给cv_split。 - 通过为
cv_split添加两列来准备cv_data:train:在splits列上映射training(),得到各折的训练数据框。validate:在splits列上映射testing(),得到各折的验证数据框。
交互式实操练习
通过完成这段示例代码来试试这个练习。
set.seed(42)
# Prepare the data frame containing the cross validation partitions
cv_split <- vfold_cv(___, v = ___)
cv_data <- cv_split %>%
mutate(
# Extract the train data frame for each split
train = map(___, ~___(.x)),
# Extract the validate data frame for each split
validate = map(___, ~___(.x))
)
# Use head() to preview cv_data
head(cv_data)