行列へ
EducationField には6つの異なる値があると特定しましたが、新しいデータでモデルを実行すると、ほかの値が現れる可能性があると考えています。これに備えて、50語のハッシュインデックスを作成します。textrecipes パッケージ、attrition_train と attrition_test の分割はすでに読み込まれています。
この演習はコースの一部です
Rで学ぶ特徴量エンジニアリング
演習の手順
- レシピに
EducationFieldの dummy_hash インデックスを生成するステップを追加します。 - レシピを準備(prep)します。
- 準備済みのレシピを bake します。
- 焼き上がった(baked)レシピのテーブルと
EducationFieldの値を1つのテーブルに結合し、先頭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)]