Interaction ที่มีค่าสัมประสิทธิ์เข้าใจง่าย
โมเดลก่อนหน้าที่มี interaction term ให้ค่าสัมประสิทธิ์ที่ตีความได้ยากนิดหน่อย เพื่อให้เข้าใจสิ่งที่โมเดลพยากรณ์ได้ชัดเจนขึ้น ลองปรับสูตรใหม่เพื่อให้ได้ค่าสัมประสิทธิ์ที่อ่านง่ายขึ้น จากนั้นเปรียบเทียบผลลัพธ์กับโมเดลที่แยกตามช่วงอายุบ้าน (mdl_0_to_15, mdl_15_to_30 และ mdl_30_to_45)
taiwan_real_estate, mdl_0_to_15, mdl_15_to_30 และ mdl_30_to_45 พร้อมใช้งานแล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Regression ระดับกลางด้วย statsmodels ใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Model price vs. house age plus an interaction, no intercept
mdl_readable_inter = ____
# Print the coefficients for mdl_0_to_15
print("mdl_0_to_15 coefficients:", "\n", ____)
# Print the coefficients for mdl_15_to_30
print("mdl_15_to_30 coefficients:", "\n", ____)
# Print the coefficients for mdl_30_to_45
print("mdl_30_to_45 coefficients:", "\n", ____)
# Print the coefficients for mdl_readable_inter
print("\n", "mdl_readable_inter coefficients:", "\n", mdl_readable_inter.params)