開始使用免費開始

進入矩陣

你已經找出 EducationField 有 6 個不同的值。不過你懷疑在把模型套用到新資料時,可能還會出現其他值。為了預先因應,你將建立一個包含 50 個詞元的雜湊索引。textrecipes 套件,以及 attrition_trainattrition_test 的分割資料都已載入。

本練習屬於課程

R 的特徵工程

檢視課程

練習說明

  • 在 recipe 中新增一步,為 EducationField 產生 dummy_hash 索引。
  • 預備(prepare)這個 recipe。
  • 將預備好的 recipe 進行 bake。
  • 將烘焙後的資料表與 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)]
編輯並執行程式碼