การแปลความหมายของสัมประสิทธิ์

Generalized Linear Models ใน Python

Ita Cirovic Donev

Data Science Consultant

สัมประสิทธิ์ของโมเดล

สรุปค่าทางสถิติของโมเดลที่ฟิตแล้ว โดยไฮไลต์คอลัมน์ coef

Generalized Linear Models ใน Python

สัมประสิทธิ์ beta

  • $\beta > 0 \rightarrow$ เส้นโค้งขาขึ้น

โมเดล Logistic ที่ฟิตระหว่าง arsenic กับ switch

  • $\beta < 0 \rightarrow$ เส้นโค้งขาลง

โมเดล Logistic ที่ฟิตระหว่าง distance100 กับ switch

Generalized Linear Models ใน Python

Linear vs Logistic

LINEAR MODEL

glm('y ~ weight', 
    data = crab, 
    family = sm.families.Gaussian())

$\mu = -0.14 + \color{#B21AB4}{0.32}*weight$

ทุกการเพิ่มขึ้น หนึ่งหน่วย ของ weight

  • $\text{\color{#B21AB4}{ความน่าจะเป็นที่ประมาณได้}}$ เพิ่มขึ้น 0.32

LOGIT MODEL

glm('y ~ weight', 
    data = crab, 
    family = sm.families.Binomial())

$log(odds) = -3.69 + \color{#228FF5}{1.8}*weight$

ทุกการเพิ่มขึ้น หนึ่งหน่วย ของ weight

  • $\text{\color{#228FF5}{log(odds)}}$ เพิ่มขึ้น 1.8
Generalized Linear Models ใน Python

การแปลความหมาย Log Odds

  • โมเดล Logistic $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1x_1 $$

  • เพิ่ม $x$ หนึ่งหน่วย $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1\color{blue}{(x_1+1)} $$

Generalized Linear Models ใน Python

การแปลความหมาย Log Odds

  • โมเดล Logistic $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1x_1 $$

  • เพิ่ม $x$ หนึ่งหน่วย $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1\color{blue}{(x_1+1)} = \beta_0 + \color{blue}{\beta_1x_1+\beta_1} $$

  • หา Exponential $$ (\frac{\mu}{1-\mu}) = \color{red}{\exp(\beta_0 + \beta_1x_1)}\color{blue}{\exp(\beta_1)} $$

สรุป $\rightarrow$ $\color{red}{\text{odds}}$ ถูกคูณด้วย $\color{blue}{\exp(\beta_1)}$

Generalized Linear Models ใน Python

การแปลความหมาย Log Odds

  • โมเดลปู y ~ weight $$ log(\frac{\mu}{1-\mu}) = -3.6947 + \color{blue}{1.815}*weight $$

  • Odds ของการมีปูดาวเทียมเพิ่มขึ้น $\color{blue}{\exp(1.815) = 6.14}$ เท่า เมื่อ weight เพิ่มขึ้นหนึ่งหน่วย

Generalized Linear Models ใน Python

การแปลความหมาย Log Odds

  • โมเดลปู y ~ weight $$ log(\frac{\mu}{1-\mu}) = \color{blue}{-3.6947} + 1.8151*weight $$

  • Odds ของการมีปูดาวเทียมเพิ่มขึ้น $\exp(1.8151) = 6.14$ เท่า เมื่อ weight เพิ่มขึ้นหนึ่งหน่วย

  • สัมประสิทธิ์ Intercept $\color{blue}{-3.6947}$ หมายถึง Log Odds พื้นฐาน
    • $\color{blue}{\exp(-3.6947)=0.0248}$ คือ Odds เมื่อ $weight = 0$
Generalized Linear Models ใน Python

ความน่าจะเป็น vs Logistic Fit

กราฟ Logistic Fit บน Scatterplot ของชั่วโมงการเรียนกับผล pass/fail

Generalized Linear Models ใน Python

ความน่าจะเป็น vs Logistic Fit

แสดงการเปลี่ยนแปลงความน่าจะเป็นเพียงเล็กน้อยจาก Logistic Fit และค่าตัวแปรอธิบาย

Generalized Linear Models ใน Python

ความน่าจะเป็น vs Logistic Fit

แสดงการเปลี่ยนแปลงความน่าจะเป็นขนาดใหญ่จาก Logistic Fit และค่าตัวแปรอธิบาย

  • ความชัน $\rightarrow \beta \times \mu(1-\mu)$
Generalized Linear Models ใน Python

ความน่าจะเป็น vs Logistic Fit

แสดงการเปลี่ยนแปลงความน่าจะเป็นสูงสุดจาก Logistic Fit และค่าตัวแปรอธิบาย

  • ความชัน $\rightarrow \beta \times \mu(1-\mu)$
Generalized Linear Models ใน Python

คำนวณการเปลี่ยนแปลงของความน่าจะเป็นที่ประมาณได้

# Choose x (weight) and extract model coefficients
x = 1.5
intercept, slope = model_GLM.params
# Compute estimated probability
est_prob = np.exp(intercept + slope * x)/(1 + np.exp(intercept + slope * x))
0.2744
# Compute incremental change in estimated probability given x
ic_prob = slope * est_prob * (1 - est_prob)
0.3614
Generalized Linear Models ใน Python

อัตราการเปลี่ยนแปลงของความน่าจะเป็นสำหรับแต่ละค่า x

$logit = -3.6947 + 1.8151*weight$

Generalized Linear Models ใน Python

มาฝึกกันเถอะ!

Generalized Linear Models ใน Python

Preparing Video For Download...