Menafsirkan koefisien

Generalized Linear Models di Python

Ita Cirovic Donev

Data Science Consultant

Koefisien model

Ringkasan statistik model terpasang, dengan kolom coef disorot.

Generalized Linear Models di Python

Koefisien beta

  • $\beta > 0 \rightarrow$ kurva naik

Kecocokan model logistik arsenic dan switch.

  • $\beta < 0 \rightarrow$ kurva turun

Kecocokan model logistik distance100 dan switch.

Generalized Linear Models di Python

Linear vs logistik

MODEL LINEAR

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

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

Untuk setiap kenaikan berat 1 satuan

  • $\text{\color{#B21AB4}{probabilitas taksiran}}$ naik 0.32

MODEL LOGIT

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

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

Untuk setiap kenaikan berat 1 satuan

  • $\text{\color{#228FF5}{log(odds)}}$ naik 1.8
Generalized Linear Models di Python

Interpretasi log-odds

  • Model logistik $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1x_1 $$

  • Naikkan $x$ satu satuan $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1\color{blue}{(x_1+1)} $$

Generalized Linear Models di Python

Interpretasi log-odds

  • Model logistik $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1x_1 $$

  • Naikkan $x$ satu satuan $$ log(\frac{\mu}{1-\mu}) = \beta_0 + \beta_1\color{blue}{(x_1+1)} = \beta_0 + \color{blue}{\beta_1x_1+\beta_1} $$

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

Kesimpulan $\rightarrow$ $\color{red}{\text{odds}}$ dikalikan $\color{blue}{\exp(\beta_1)}$

Generalized Linear Models di Python

Interpretasi log-odds

  • Model kepiting y ~ weight $$ log(\frac{\mu}{1-\mu}) = -3.6947 + \color{blue}{1.815}*weight $$

  • Odds kepiting satelit dikali $\color{blue}{\exp(1.815) = 6.14}$ untuk kenaikan berat 1 satuan

Generalized Linear Models di Python

Interpretasi log-odds

  • Model kepiting y ~ weight $$ log(\frac{\mu}{1-\mu}) = \color{blue}{-3.6947} + 1.8151*weight $$

  • Odds kepiting satelit dikali $\exp(1.8151) = 6.14$ untuk kenaikan berat 1 satuan

  • Intersep $\color{blue}{-3.6947}$ menyatakan log-odds dasar
    • $\color{blue}{\exp(-3.6947)=0.0248}$ adalah odds saat $weight = 0$.
Generalized Linear Models di Python

Probabilitas vs kecocokan logistik

Kecocokan logistik pada scatterplot jam belajar dan lulus/gagal tes.

Generalized Linear Models di Python

Probabilitas vs kecocokan logistik

Ilustrasi perubahan kecil pada probabilitas menurut kecocokan logistik dan nilai peubah penjelas.

Generalized Linear Models di Python

Probabilitas vs kecocokan logistik

Ilustrasi perubahan besar pada probabilitas menurut kecocokan logistik dan nilai peubah penjelas.

  • kemiringan $\rightarrow \beta \times \mu(1-\mu)$
Generalized Linear Models di Python

Probabilitas vs kecocokan logistik

Ilustrasi perubahan terbesar pada probabilitas menurut kecocokan logistik dan nilai peubah penjelas.

  • kemiringan $\rightarrow \beta \times \mu(1-\mu)$
Generalized Linear Models di Python

Hitung perubahan pada probabilitas taksiran

# 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 di Python

Laju perubahan probabilitas untuk setiap x

$logit = -3.6947 + 1.8151*weight$

Generalized Linear Models di Python

Ayo berlatih!

Generalized Linear Models di Python

Preparing Video For Download...