बाइनरी डेटा और लॉजिस्टिक रिग्रेशन

Python में Generalized Linear Models

Ita Cirovic Donev

Data Science Consultant

बाइनरी प्रतिक्रिया डेटा

  • दो-वर्ग प्रतिक्रिया $\rightarrow \large{\texttt{\color{#079EA1}{0},\color{#ED715F}{1}}}$

उदाहरण:

  • क्रेडिट स्कोरिंग $\rightarrow \texttt{\color{#ED715F}{"Default"}/\color{#079EA1}{"Non-Default"}}$
  • टेस्ट पास/फेल $\rightarrow \texttt{\color{#079EA1}{"Pass"}/\color{#ED715F}{"Fail"}}$
  • फ्रॉड डिटेक्शन $\rightarrow \texttt{\color{#ED715F}{"Fraud"}/\color{#079EA1}{"No-Fraud"}}$
  • प्रोडक्ट का चुनाव $\rightarrow \texttt{\color{#2485F2}{"Product ABC"}/\color{#F2AC30}{"Product XYZ"}}$
Python में Generalized Linear Models

बाइनरी डेटा

UNGROUPED

  • एक घटना
  • एक सिक्का उछालें
  • संभावित दो परिणाम: 0/1
  • $Bernoulli(p)$ या
  • $Binomial(n=1,p)$

GROUPED

  • कई घटनाएँ
  • कई सिक्के उछालें
  • दिए गए $n$ ट्रायल में सफलताओं की संख्या
  • $Binomial(n,p)$
Python में Generalized Linear Models

लॉजिस्टिक फंक्शन

पढ़ाई के घंटों और टेस्ट पास/फेल प्रतिक्रिया (0/1) का स्कैटरप्लॉट

Python में Generalized Linear Models

लॉजिस्टिक फंक्शन

पढ़ाई के घंटों और टेस्ट पास/फेल प्रतिक्रिया (0/1) का स्कैटरप्लॉट

  • टेस्ट परिणाम: $PASS=1$ या $FAIL=0$

  • क्या मॉडल करना है

$P(y=1)=\beta_0 + \beta_1x_1$

$P(\text{Pass})=\beta_0 + \beta_1 \times \text{Hours of study}$

Python में Generalized Linear Models

लॉजिस्टिक फंक्शन

पढ़ाई के घंटों और टेस्ट पास/फेल प्रतिक्रिया (0/1) पर लॉजिस्टिक फिट

  • टेस्ट परिणाम: $PASS=1$ या $FAIL=0$

  • मॉडल करना चाहते हैं

$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))}$

Python में Generalized Linear Models

ऑड्स और ऑड्स रेशियो

       

$$ ODDS = \frac{\text{event occuring}}{\text{event NOT occuring}} $$

       

$$ \text{ODDS RATIO} = \frac{odds 1}{odds 2} $$

Python में Generalized Linear Models

ऑड्स उदाहरण

  • 4 गेम 3 जीत और 1 हार का क्रम

  • ऑड्स 3 से 1 हैं ऑड्स की दृश्य गणना: अंश में 3 जीत बॉक्स, हर में 1 हार बॉक्स.

Python में Generalized Linear Models

ऑड्स और प्रॉबेबिलिटीज

  $$ \text{odds} \neq \text{probability} $$

  $$ \text{odds} = \frac{\text{probability}}{1-\text{probability}} $$

  $$ \text{probability} = \frac{\text{odds}}{1+\text{odds}} $$

Python में Generalized Linear Models

प्रॉबेबिलिटी मॉडल से लॉजिस्टिक रिग्रेशन तक

 

चरण 1. प्रॉबेबिलिटी मॉडल

$E(y)=\mu=P(y=1)=\beta_0 + \beta_1x_1$

 

चरण 2. लॉजिस्टिक फंक्शन

$f(z) = \large{\frac{1}{(1+\exp(-z))}}$

 

चरण 3. लॉजिस्टिक फंक्शन लागू करें $\rightarrow$ INVERSE-LOGIT

$\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)}}$

Python में Generalized Linear Models

प्रॉबेबिलिटी मॉडल से लॉजिस्टिक रिग्रेशन तक

 

  • प्रॉबेबिलिटी $\rightarrow$ ऑड्स $$ ODDS=\frac{\mu}{1-\mu} = exp{(\beta_0+\beta_1x_1)} $$  
  • लॉग ट्रांसफॉर्मेशन $\rightarrow \color{#CF5383}{\text{LOGISTIC REGRESSION}}$

  $$ LOGIT(\mu)=log(\frac{\mu}{1-\mu}) = \beta_0+\beta_1x_1 $$

Python में Generalized Linear Models

Python में लॉजिस्टिक रिग्रेशन

फंक्शन - glm()

model_GLM = glm(formula = 'y ~ x',                        
                data = my_data, 
                family = sm.families.Binomial()).fit

इनपुट

y = [0,1,1,0,...]
y = ['No','Yes','Yes',...]
y = ['Fail','Pass','Pass',...]
Python में Generalized Linear Models

अभ्यास करते हैं!

Python में Generalized Linear Models

Preparing Video For Download...