Generalized Linear Models ใน Python
Ita Cirovic Donev
Data Science Consultant

$\color{#00A388}{\text{salary}} \sim \color{#FF6138}{\text{experience}}$
$\normalsize{\color{#00A388}{\text{salary}} = \beta_0 + \beta_1\times\color{#FF6138}{\text{experience}} + \epsilon}$
$\normalsize{\color{#00A388}y = \beta_0 + \beta_1x_1 + \epsilon}$

$\color{#00A388}{\text{salary}} \sim \color{#FF6138}{\text{experience}}$
$\color{#00A388}{\text{salary}} = \beta_0 + \beta_1\times{\text{experience}} + \epsilon$
$\color{#00A388}y = \beta_0 + \beta_1x_1 + \epsilon$
เมื่อ:
$\color{#00A388}y$ - ตัวแปรตอบสนอง (output)

$\color{#00A388}{\text{salary}} \sim \color{#FF6138}{\text{experience}}$
$\normalsize{\color{#00A388}{\text{salary}} = \beta_0 + \beta_1\times\color{#FF6138}{\text{experience}} + \epsilon}$
$\normalsize{\color{#00A388}y = \beta_0 + \beta_1\color{#FF6138}{x_1} + \epsilon}$
เมื่อ:
$y$ - ตัวแปรตอบสนอง (output)
$\color{#FF6138}x$ - ตัวแปรอธิบาย (input)

$\color{#00A388}{\text{salary}} \sim \color{#FF6138}{\text{experience}}$
$\normalsize{\color{#00A388}{\text{salary}} = \color{#007AFF}{\beta_0} + \color{#007AFF}{\beta_1}\times\color{#FF6138}{\text{experience}} + \epsilon}$
$\normalsize{\color{#00A388}y = \color{#007AFF}{\beta_0} + \color{#007AFF}{\beta_1}\color{#FF6138}{x_1} + \epsilon}$
เมื่อ:
$y$ - ตัวแปรตอบสนอง (output)
$x$ - ตัวแปรอธิบาย (input)
$\color{#007AFF}{\beta}$ - พารามิเตอร์ของโมเดล
$\color{#007AFF}{\beta_0}$ - ค่าตัดแกน (intercept)
$\color{#007AFF}{\beta_1}$ - ความชัน (slope)

$\color{#00A388}{\text{salary}} \sim \color{#FF6138}{\text{experience}}$
$\normalsize{\color{#00A388}{\text{salary}} = \color{#007AFF}{\beta_0} + \color{#007AFF}{\beta_1}\times\color{#FF6138}{\text{experience}} + \color{#B12BFF}\epsilon}$
$\normalsize{\color{#00A388}y = \color{#007AFF}{\beta_0} + \color{#007AFF}{\beta_1}\color{#FF6138}{x_1} + \color{#B12BFF}\epsilon}$
เมื่อ:
$y$ - ตัวแปรตอบสนอง (output)
$x$ - ตัวแปรอธิบาย (input)
$\color{#007AFF}{\beta}$ - พารามิเตอร์ของโมเดล
$\color{#007AFF}{\beta_0}$ - ค่าตัดแกน (intercept)
$\color{#007AFF}{\beta_1}$ - ความชัน (slope)
$\color{#B12BFF}{\epsilon}$ - ความคลาดเคลื่อนแบบสุ่ม (random error)
LINEAR MODEL - ols()
from statsmodels.formula.api import ols
model = ols(formula = 'y ~ X',
data = my_data).fit()
GENERALIZED LINEAR MODEL - glm()
import statsmodels.api as sm
from statsmodels.formula.api import glm
model = glm(formula = 'y ~ X',
data = my_data,
family = sm.families.____).fit()

$$ \normalsize{{\text{salary} = \color{blue}{25790} + \color{blue}{9449}\times\text{experience}}} $$
ฟังก์ชันการถดถอย
$\normalsize{E[y] = \mu = \beta_0 + \beta_1x_1}$
ข้อสมมติ

| ชื่อตัวแปร | คำอธิบาย |
|---|---|
sat |
จำนวนปูตัวผู้ที่อาศัยอยู่ในรัง |
y |
มีปูตัวผู้อย่างน้อย 1 ตัวในรัง; 0/1 |
weight |
น้ำหนักของปูตัวเมียในกิโลกรัม |
width |
ความกว้างของปูตัวเมียในเซนติเมตร |
color |
1 - อ่อนปานกลาง, 2 - ปานกลาง, 3 - เข้มปานกลาง, 4 - เข้ม |
spine |
1 - ปกติทั้งคู่, 2 - สึกหรือหักข้างหนึ่ง, 3 - สึกหรือหักทั้งคู่ |
$\text{satellite crab} \sim \text{female crab weight}$
y ~ weight
$P(\text{satellite crab is present})=P(y=1)$






Generalized Linear Models ใน Python