擬合 Poisson 迴歸
延續使用 crab 資料集,你將在這個練習中擬合第一個 Poisson 迴歸模型。
crab 資料集已預先載入工作區。
本練習屬於課程
Generalized Linear Models in Python
練習說明
- 將
statsmodels.api函式庫以sm名稱匯入。 - 從
statsmodels.formula.api匯入glm。 - 使用
Poisson()作為反應分配,擬合以sat為反應變數、weight為解釋變數的 Poisson 迴歸。 - 使用
.summary()顯示模型結果。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import libraries
import ____.____ as sm
from ____.formula.api import ____
# Fit Poisson regression of sat by weight
model = ____('____ ~ ____', data = ____, family = ____.____.____).____
# Display model results
____(model.____)