如何建立 GLM?

Generalized Linear Models in Python

Ita Cirovic Donev

Data Science Consultant

GLM 的組成

隨機成分的公式表示

Generalized Linear Models in Python

GLM 的組成

隨機與系統成分的公式表示

Generalized Linear Models in Python

GLM 的組成

含交互作用之隨機與系統成分的公式表示。

Generalized Linear Models in Python

GLM 的組成

含交互作用與曲線效果之隨機與系統成分的公式表示。

Generalized Linear Models in Python

GLM 的組成

隨機與系統成分及連結函數的公式表示

Generalized Linear Models in Python

Continuous $\rightarrow$ 線性迴歸

連續型隨機變數的分布圖。

資料型別:連續
定義域:$(-\infty,\infty)$
範例:房價、薪資、身高

族群Gaussian()
連結:identity
$g(\mu) = \mu = E(y)$

模型 = 線性迴歸

Generalized Linear Models in Python

Binary $\rightarrow$ 邏輯斯迴歸

二元隨機變數的分布圖。

資料型別:二元
定義域:$0,1$
範例:True/False

族群Binomial()
連結:logit

模型 = 邏輯斯迴歸

Generalized Linear Models in Python

Count $\rightarrow$ Poisson 迴歸

計數資料的分布圖。

資料型別:計數
定義域:$0, 1, 2, ..., \infty$
範例:得票數、颶風次數

族群Poisson()
連結:logarithm

模型 = Poisson 迴歸

Generalized Linear Models in Python

連結函數

密度 連結:$\eta=g(\mu)$ 預設連結 glm(family=...)
Normal $\eta = \mu$ identity Gaussian()
Poisson $\eta = log(\mu)$ logarithm Poisson()
Binomial $\eta = log[p/(1-p)]$ logit Binomial()
Gamma $\eta = 1/\mu$ inverse Gamma()
Inverse Gaussian $\eta = 1/\mu^2$ inverse squared InverseGaussian()
Generalized Linear Models in Python

GLM 的優點

  • 統一架構,涵蓋多種資料分布
    • 指數族分布
  • 連結函數
    • 轉換 y 的期望值
    • 允許線性組合
    • 多項線性模型技巧亦適用於 GLM
Generalized Linear Models in Python

一起來練習吧!

Generalized Linear Models in Python

Preparing Video For Download...