เข้าสู่เมทริกซ์
คุณพบว่า EducationField มีค่าที่แตกต่างกันอยู่ 6 ค่า แต่คาดว่าอาจมีค่าใหม่ปรากฏขึ้นเมื่อนำโมเดลไปใช้กับข้อมูลใหม่ เพื่อรับมือกับสิ่งนี้ คุณจะสร้าง hash index ที่มี 50 เทอม โดยแพ็กเกจ textrecipes รวมถึงชุดข้อมูล attrition_train และ attrition_test ถูกโหลดไว้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Feature Engineering in R
คำแนะนำการฝึกหัด
- เพิ่ม step ลงใน recipe เพื่อสร้าง dummy_hash index สำหรับ
EducationField - Prepare recipe
- Bake recipe ที่ prepared แล้ว
- นำตารางที่ได้จาก 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)]