Modele Liniare Generalizate în Python
Ita Cirovic Donev
Data Science Consultant
Exemple:
NEGRUPAT
GRUPAT


Rezultatul testului: $PASS=1$ sau $FAIL=0$
Dorim să modelăm
$P(y=1)=\beta_0 + \beta_1x_1$
$P(\text{Pass})=\beta_0 + \beta_1 \times \text{Hours of study}$

Rezultatul testului: $PASS=1$ sau $FAIL=0$
Dorim să modelăm
$P(y=1)=\beta_0 + \beta_1x_1$
$P(\text{Pass})=\beta_0 + \beta_1 \times \text{Hours of study}$
$f(z) = \frac{1}{(1+\exp(-z))}$
$$ ODDS = \frac{\text{event occuring}}{\text{event NOT occuring}} $$
$$ \text{ODDS RATIO} = \frac{odds 1}{odds 2} $$
4 meciuri

Cotele sunt 3 la 1

$$ \text{odds} \neq \text{probability} $$
$$ \text{odds} = \frac{\text{probability}}{1-\text{probability}} $$
$$ \text{probability} = \frac{\text{odds}}{1+\text{odds}} $$
Pasul 1. Model de probabilitate
$E(y)=\mu=P(y=1)=\beta_0 + \beta_1x_1$
Pasul 2. Funcția logistică
$f(z) = \large{\frac{1}{(1+\exp(-z))}}$
Pasul 3. Aplicarea funcției logistice $\rightarrow$ LOGIT INVERS
$\mu = \large{\frac{1}{1+\exp(-(\beta_0+\beta_1x_1))}} = \large{\frac{\exp(\beta_0+\beta_1x_1)}{1+\exp(\beta_0+\beta_1x_1)}}$
$1-\mu = \large{\frac{1}{1+\exp(\beta_0+\beta_1x_1)}}$
$$ LOGIT(\mu)=log(\frac{\mu}{1-\mu}) = \beta_0+\beta_1x_1 $$
Funcție - glm()
model_GLM = glm(formula = 'y ~ x',
data = my_data,
family = sm.families.Binomial()).fit
Date de intrare
y = [0,1,1,0,...]
y = ['No','Yes','Yes',...]
y = ['Fail','Pass','Pass',...]
Modele Liniare Generalizate în Python