การทำนายด้วยโมเดลที่มี Interaction
เช่นเดียวกับโมเดล regression ทุกตัวที่ผ่านมา ขั้นตอนที่น่าสนใจที่สุดคือการทำนายผล โชคดีที่กระบวนการเขียนโค้ดในกรณีนี้เหมือนกับโมเดลที่ไม่มี interaction ทุกประการ — statsmodels จัดการคำนวณ interaction ให้โดยอัตโนมัติ สิ่งเดียวที่ต้องจำคือเทคนิคการสร้างชุดค่าผสมของตัวแปรอธิบาย
mdl_price_vs_both_inter พร้อมใช้งานในฐานะโมเดลที่ฝึกแล้ว และ itertools.product ถูกโหลดไว้แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Regression ระดับกลางด้วย statsmodels ใน Python
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Create n_convenience as an array of numbers from 0 to 10
n_convenience = ____
# Extract the unique values of house_age_years
house_age_years = ____
# Create p as all combinations of values of n_convenience and house_age_years
p = ____
# Transform p to a DataFrame and name the columns
explanatory_data = ____
# Print it
print(explanatory_data)