การตีความการอนุมานของโมเดล

Generalized Linear Models ใน Python

Ita Cirovic Donev

Data Science Consultant

การประมาณค่าสัมประสิทธิ์ beta

  • การประมาณค่าความน่าจะเป็นสูงสุด (MLE)
  • ค่าสัมประสิทธิ์ที่ประมาณได้ $\hat\beta$
    • log-likelihood มีค่าสูงสุด

ฟังก์ชัน Likelihood

Generalized Linear Models ใน Python

การประมาณค่าสัมประสิทธิ์ beta

  • Iteratively reweighted least squares (IRLS)

ผลลัพธ์สรุปของโมเดลที่ฟิตแล้ว

Generalized Linear Models ใน Python

การทดสอบนัยสำคัญ

ผลลัพธ์สรุปของโมเดลที่ฟิตแล้ว พร้อมไฮไลต์สถิติที่เกี่ยวข้องกับการประมาณค่าสัมประสิทธิ์

Generalized Linear Models ใน Python

ค่าความคลาดเคลื่อนมาตรฐาน (SE)

  • ยอดแบนราบกว่า
    $\rightarrow$ ระบุตำแหน่งค่าสูงสุดได้ยากกว่า
    $\rightarrow$ SE ใหญ่กว่า

ภาพแสดง Likelihood เมื่อ Standard Error มีขนาดใหญ่

  • ยอดแหลมชัดกว่า
    $\rightarrow$ ระบุตำแหน่งค่าสูงสุดได้ชัดเจนกว่า
    $\rightarrow$ SE เล็กกว่า

ภาพแสดง Likelihood เมื่อ Standard Error มีขนาดเล็ก

Generalized Linear Models ใน Python

การคำนวณค่าความคลาดเคลื่อนมาตรฐาน

# Extract variance-covariance matrix
print(model_GLM.cov_params())
           Intercept    weight
Intercept   0.774762 -0.325087
weight     -0.325087  0.141903
# Compute standard error for weight
std_error = np.sqrt(0.141903)
0.3767

เมทริกซ์ความแปรปรวนร่วม

ภาพแสดงเมทริกซ์ความแปรปรวนร่วม

Generalized Linear Models ใน Python

การทดสอบนัยสำคัญ

  • z-statistic $$ \color{#2485F2}{z=\hat\beta/SE} $$

  • $\color{#2485F2}{z}$ มีค่ามาก $\Rightarrow$ สัมประสิทธิ์ $\ne0$ $\Rightarrow$ ตัวแปรมีนัยสำคัญ

  • ค่าตัดสินเบื้องต้น: 2

ตัวอย่าง: โมเดลปูเกือกม้า
y ~ weight

$z = 1.8151/0.377 = 4.819$

Generalized Linear Models ใน Python

ช่วงความเชื่อมั่นสำหรับ beta

  • ความไม่แน่นอนของค่าประมาณ
  • ช่วงความเชื่อมั่น 95% สำหรับ $\beta$

$$ [\color{#5A5AF3}{lower},\color{#D8498E}{upper}] $$

$$ [\color{#5A5AF3}{\hat\beta - 1.96 \times SE},\color{#D8498E}{\hat\beta+1.96 \times SE}] $$

Generalized Linear Models ใน Python

การคำนวณช่วงความเชื่อมั่น

ตัวอย่าง: โมเดลปูเกือกม้า

                 coef    std err   
<hr />-------------------------------
Intercept     -3.6947      0.880  
weight         1.8151      0.377  

Generalized Linear Models ใน Python

การดึงช่วงความเชื่อมั่น

print(model_GLM.conf_int())
                  0         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Generalized Linear Models ใน Python

การดึงช่วงความเชื่อมั่น

print(model_GLM.conf_int())
              lower         1
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Generalized Linear Models ใน Python

การดึงช่วงความเชื่อมั่น

print(model_GLM.conf_int())
                  0     upper
Intercept -5.419897 -1.969555
weight     1.076826  2.553463
Generalized Linear Models ใน Python

ช่วงความเชื่อมั่นสำหรับอัตราต่อรอง

  1. ดึงช่วงความเชื่อมั่นของ $\beta$

  2. ยกกำลัง e ให้กับค่าปลายช่วง

print(np.exp(model_GLM.conf_int()))
                  0          1
Intercept  0.004428   0.139519
weight     2.935348  12.851533
Generalized Linear Models ใน Python

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

Generalized Linear Models ใน Python

Preparing Video For Download...