Model fit interpreteren

Generalized Linear Models in Python

Ita Cirovic Donev

Data Science Consultant

Parameterinschatting

  • Maximum likelihood (MLE)
  • Iteratief gewogen kleinste kwadraten (IRLS)
Generalized Linear Models in Python

De responsfunctie

  • Poisson-regressiemodel $$ log(\lambda)=\beta_0+\beta_1x_1 $$

  • De responsfunctie: $$ \lambda=exp(\beta_0 + \beta_1x_1) $$                                                  of $$ \lambda=exp(\beta_0) \times exp(\beta_1x_1) $$

Generalized Linear Models in Python

De responsfunctie

  • Poisson-regressiemodel $$ log(\lambda)=\beta_0+\beta_1x_1 $$

  • De responsfunctie: $$ \lambda=exp(\beta_0 + \beta_1x_1) $$                                                  of $$ \lambda=exp(\beta_0) \color{red}{\times} exp(\beta_1x_1) $$

Generalized Linear Models in Python

Interpretatie van parameters

  • $exp(\beta_0)$

    • Het effect op het gemiddelde $\lambda$ bij $x=0$
  • $exp(\beta_1)$

    • Het multiplicatieve effect op het gemiddelde $\lambda$ bij een toename van 1 eenheid in $x$
Generalized Linear Models in Python

Effect van coëfficiënt interpreteren

  • Als $\color{#FF550D}{\beta_1 > 0}$
    • $exp(\beta_1)>1$
    • $\lambda$ is $\color{#FF550D}{exp(\beta_1)\text{ keer groter}}$ dan bij $x=0$
  • Als $\color{#D04A73}{\beta<0}$
    • $exp(\beta_1)<1$
    • $\lambda$ is $\color{#D04A73}{exp(\beta_1) \text{ keer kleiner}}$ dan bij $x=0$
  • Als $\color{#0099FF}{\beta_1 = 0}$
    • $exp(\beta_1)=1$
    • $\lambda=exp(\beta_0)$
    • Multiplicatieve factor is 1
    • $y$ en $x$ zijn $\text{\color{#0099FF}{niet gerelateerd}}$
Generalized Linear Models in Python

Voorbeeld

model = glm('sat ~ weight', data = crab, 
            family = sm.families.Poisson()).fit()
                 Generalized Linear Model Regression Results (print cut)                 
=============================================================================
                 coef    std err          z      P>|z|      [0.025     0.975]
-----------------------------------------------------------------------------
Intercept     -0.4284      0.179     -2.394      0.017      -0.779     -0.078
weight         0.5893      0.065      9.064      0.000       0.462      0.717
=============================================================================
Generalized Linear Models in Python

Voorbeeld - interpretatie van beta

  • Haal modelcoëfficiënten op
    model.params
    
Intercept   -0.428405
weight       0.589304
  • Bereken het effect
    np.exp(0.589304)
    
1.803
Generalized Linear Models in Python

Betrouwbaarheidsinterval voor ...

  • $\beta_1$
print(model.conf_int())
                  0         1
Intercept -0.779112 -0.077699
weight     0.461873  0.716735
  • Het multiplicatieve effect op het gemiddelde
print(np.exp(crab_fit.conf_int()))
                  0         1
Intercept  0.458813  0.925243
weight     1.587044  2.047737
Generalized Linear Models in Python

Laten we oefenen!

Generalized Linear Models in Python

Preparing Video For Download...