走进矩阵
您已找到 EducationField 的 6 个不同取值。但您怀疑在将模型应用到新数据时还会出现其他取值。为此做准备,您将创建一个包含 50 个项的哈希索引。textrecipes 包、attrition_train 和 attrition_test 拆分已加载。
本练习是课程的一部分
R 中的特征工程
练习说明
- 在配方中添加一步,为
EducationField生成 dummy_hash 索引。 - 预处理该配方。
- 烘焙预处理后的配方。
- 将烘焙后的配方表与
EducationField值绑定为一张表,并打印前 7 行,以及第 1 列和第 18 到 20 列。
交互式实操练习
通过完成这段示例代码来试试这个练习。
recipe <- recipe(~EducationField, data = attrition_train) %>%
# Add a step to the recipe that generates a dummy_hash index for EducationField
___(EducationField, prefix = NULL, signed = FALSE, num_terms = 50L)
# Prepare the recipe
object <- recipe %>%
___
# Bake the prepped recipe
baked <- ___(object, new_data = attrition_test)
# Bind the baked recipe table and the EducationField values into one table
bind_cols(___, baked)[1:7,c(1,18:20)]