估計參數 lambda
在影片中你學到,使用對數連結函式可以把參數的線性組合帶入Poisson 迴歸模型,其形式為:
$$ log(\lambda)=\beta_0+\beta_1x_1 $$
若要得到以 lambda 表示的反應函式,我們將模型函式取指數,得到:
$$ \lambda=E(y)=exp(\beta_0 + \beta_1x_1) $$ $$ \lambda=E(y)=exp(\beta_0) \times exp(\beta_1x_1) $$
在這個練習中,你會用這套公式配合 horseshoe 蟹的資料,計算雌蟹寬度對應的平均 \(y\) 的估計值。
資料集 crab 已預先載入到工作環境中。
本練習屬於課程
Generalized Linear Models in Python
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Import libraries
import ____.____ as sm
from ____.formula.api import ____
# Fit Poisson regression of sat by width
model = ____('____ ~ ____', data = ____, family = ____.____.____).____
# Display model results
____(model.____)