การ Fit โมเดล Negative Binomial
Negative Binomial ช่วยให้ค่าความแปรปรวนสามารถเกินค่าเฉลี่ยได้ ซึ่งตรงกับสิ่งที่วัดได้ในแบบฝึกหัดก่อนหน้าจากข้อมูล crab ในแบบฝึกหัดนี้ จะทบทวนการ fit โมเดล Poisson regression โดยใช้ log link function จากนั้น fit โมเดล Negative Binomial ด้วย log link function เช่นกัน
จากนั้นจะวิเคราะห์และดูว่าค่าสถิติต่าง ๆ เปลี่ยนแปลงไปอย่างไร
โมเดล crab_pois และข้อมูล crab ถูกโหลดไว้ใน workspace แล้ว
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
Generalized Linear Models ใน Python
คำแนะนำการฝึกหัด
- กำหนดสูตร (formula) สำหรับโมเดลการถดถอยโดยให้
satถูกทำนายด้วยwidth - Fit โมเดล Negative Binomial โดยใช้
NegativeBinomial()และบันทึกโมเดลเป็นcrab_NB - แสดงผลสรุปของโมเดล Poisson
crab_poisและโมเดล Negative Binomial ที่เพิ่งสร้างขึ้น
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Define the formula for the model fit
formula = '____ ~ ____'
# Fit the GLM negative binomial model using log link function
crab_NB = smf.glm(formula = ____, data = ____,
family = ____.____.____).____
# Print Poisson model's summary
print(____.____)
# Print the negative binomial model's summary
print(____.____)