จัดระเบียบสัมประสิทธิ์ของโมเดล
ในแบบฝึกหัดนี้ จะใช้ list column workflow ร่วมกับฟังก์ชัน tidy() จากแพ็กเกจ broom เพื่อดึงและสำรวจสัมประสิทธิ์ของโมเดลทั้ง 77 โมเดลที่สร้างไว้
ระลึกไว้ว่า data frame gap_models มีโมเดลที่ทำนาย อายุขัยเฉลี่ย จาก ปี สำหรับ 77 ประเทศ
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Machine Learning ใน Tidyverse
คำแนะนำการฝึกหัด
- ใช้
tidy()เพื่อเพิ่มคอลัมน์ (coef) ที่มีสถิติสัมประสิทธิ์ของแต่ละโมเดลเข้าไปใน data framegap_modelsแล้วบันทึกเป็นmodel_coef_nested - ลดรูป data frame นี้โดยใช้
unnest()เพื่อแยกสัมประสิทธิ์ออกมาใน data frame - สำรวจค่าประมาณสัมประสิทธิ์ของ feature
yearจากโมเดลทั้ง 77 โมเดล โดยพล็อต histogram ของค่าเหล่านั้น
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Extract the coefficient statistics of each model into nested data frames
model_coef_nested <- gap_models %>%
mutate(coef = map(model, ~___(.x)))
# Simplify the coef data frames for each model
model_coef <- model_coef_nested %>%
unnest(___)
# Plot a histogram of the coefficient estimates for year
model_coef %>%
filter(term == "___") %>%
ggplot(aes(x = ___)) +
geom_histogram()