การพยากรณ์ด้วยโมเดล Parallel Slopes
แม้ seaborn จะแสดงผลการพยากรณ์ของโมเดลได้อัตโนมัติผ่าน sns.regplot() แต่หากต้องการนำค่าเหล่านั้นไปใช้ในโค้ดต่อ จำเป็นต้องคำนวณเองโดยตรง
เช่นเดียวกับกรณีที่มีตัวแปรอธิบายตัวเดียว ขั้นตอนการทำงานมีสองขั้น ได้แก่ สร้าง DataFrame ของตัวแปรอธิบาย แล้วจึงเพิ่มคอลัมน์ผลการพยากรณ์
taiwan_real_estate และ mdl_price_vs_both ในฐานะโมเดลที่ฟิตแล้วพร้อมใช้งาน seaborn, ols(), matplotlib.pyplot, pandas และ numpy ถูกโหลดด้วย alias มาตรฐาน ซึ่งจะเป็นเช่นนี้ตลอดทั้งคอร์ส นอกจากนี้ยังสามารถใช้ 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(explanatory_data)