├── Multivariate Logistic Regression - Model Building
├── Logistic+Regression+-+Telecom+Churn+Case+Study (1) (1).ipynb
└── init
├── README.md
└── Univariate Logistic Regression
├── Betas+for+Logistic+Regression (1).ipynb
└── init
/Multivariate Logistic Regression - Model Building/init:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Welcome to Logistic Regression Module
2 |
3 | ## TOC:
4 | - How to download files?
5 | - What is where?
6 |
7 | ### How to download files?
8 | 
9 |
10 | Click on Code button and then click on Download ZIP
11 | OR
12 | Use `git clone https://github.com/ContentUpgrad/Logistic-Regression.git` command on your terminal if git is installed in your machine.
13 |
14 |
15 | ### What is where?
16 | The folder structure is given below:
17 | 
18 |
19 |
20 | As you can see there are two main folders when you log in:
21 |
22 | 1. **Multivariate Logistic Regression - Model Building** This is where all the code files regarding Multivariate Logistic Regression - Model Building sessions are kept
23 | 2. **Univariate Logistic Regression** This is where all the code files regarding Univariate Logistic Regression session are kept
24 |
25 | When you click on any folder you will find the code and data folders as shown below:
26 | 
27 |
28 | You will find all the code files of the session in code folder and data folder will be empty. Please note that you need to follow the instructions given in the segment for downloading data files and keep it in the data folder manually.
29 |
30 | #### Multivariate Logistic Regression - Model Building
31 | You will find the following files in the code folder of Multivariate Logistic Regression - Model Building
32 | 
33 |
34 |
35 | #### Univariate Logistic Regression
36 | You will find the following files in the code folder of Univariate Logistic Regression
37 | 
38 |
39 |
40 |
--------------------------------------------------------------------------------
/Univariate Logistic Regression/Betas+for+Logistic+Regression (1).ipynb:
--------------------------------------------------------------------------------
1 | {
2 | "cells": [
3 | {
4 | "cell_type": "code",
5 | "execution_count": null,
6 | "metadata": {},
7 | "outputs": [],
8 | "source": [
9 | "\n",
10 | "# # Recommended versions\n",
11 | "# numpy \t1.26.4\n",
12 | "# pandas\t2.2.2\n",
13 | "# matplotlib\t3.7.1\n",
14 | "# seaborn\t0.10.0\n",
15 | "# statsmodels\t0.14.4\n",
16 | "# sklearn\t1.5.2"
17 | ]
18 | },
19 | {
20 | "cell_type": "code",
21 | "execution_count": 29,
22 | "metadata": {
23 | "collapsed": true
24 | },
25 | "outputs": [],
26 | "source": [
27 | "import pandas as pd\n",
28 | "import numpy as np"
29 | ]
30 | },
31 | {
32 | "cell_type": "code",
33 | "execution_count": 30,
34 | "metadata": {
35 | "collapsed": true
36 | },
37 | "outputs": [],
38 | "source": [
39 | "dib = pd.read_csv('Diabetes Example Data.csv')"
40 | ]
41 | },
42 | {
43 | "cell_type": "code",
44 | "execution_count": 31,
45 | "metadata": {},
46 | "outputs": [
47 | {
48 | "data": {
49 | "text/html": [
50 | "
\n",
51 | "\n",
64 | "
\n",
65 | " \n",
66 | " \n",
67 | " | \n",
68 | " Blood Sugar Level | \n",
69 | " Diabetes | \n",
70 | "
\n",
71 | " \n",
72 | " \n",
73 | " \n",
74 | " 0 | \n",
75 | " 190 | \n",
76 | " No | \n",
77 | "
\n",
78 | " \n",
79 | " 1 | \n",
80 | " 240 | \n",
81 | " Yes | \n",
82 | "
\n",
83 | " \n",
84 | " 2 | \n",
85 | " 300 | \n",
86 | " Yes | \n",
87 | "
\n",
88 | " \n",
89 | " 3 | \n",
90 | " 160 | \n",
91 | " No | \n",
92 | "
\n",
93 | " \n",
94 | " 4 | \n",
95 | " 200 | \n",
96 | " Yes | \n",
97 | "
\n",
98 | " \n",
99 | "
\n",
100 | "
"
101 | ],
102 | "text/plain": [
103 | " Blood Sugar Level Diabetes\n",
104 | "0 190 No\n",
105 | "1 240 Yes\n",
106 | "2 300 Yes\n",
107 | "3 160 No\n",
108 | "4 200 Yes"
109 | ]
110 | },
111 | "execution_count": 31,
112 | "metadata": {},
113 | "output_type": "execute_result"
114 | }
115 | ],
116 | "source": [
117 | "dib.head()"
118 | ]
119 | },
120 | {
121 | "cell_type": "code",
122 | "execution_count": 32,
123 | "metadata": {
124 | "collapsed": true
125 | },
126 | "outputs": [],
127 | "source": [
128 | "# Converting Yes to 1 and No to 0\n",
129 | "dib['Diabetes'] = dib['Diabetes'].map({'Yes': 1, 'No': 0})"
130 | ]
131 | },
132 | {
133 | "cell_type": "code",
134 | "execution_count": 33,
135 | "metadata": {},
136 | "outputs": [
137 | {
138 | "data": {
139 | "text/html": [
140 | "\n",
141 | "\n",
154 | "
\n",
155 | " \n",
156 | " \n",
157 | " | \n",
158 | " Blood Sugar Level | \n",
159 | " Diabetes | \n",
160 | "
\n",
161 | " \n",
162 | " \n",
163 | " \n",
164 | " 0 | \n",
165 | " 190 | \n",
166 | " 0 | \n",
167 | "
\n",
168 | " \n",
169 | " 1 | \n",
170 | " 240 | \n",
171 | " 1 | \n",
172 | "
\n",
173 | " \n",
174 | " 2 | \n",
175 | " 300 | \n",
176 | " 1 | \n",
177 | "
\n",
178 | " \n",
179 | " 3 | \n",
180 | " 160 | \n",
181 | " 0 | \n",
182 | "
\n",
183 | " \n",
184 | " 4 | \n",
185 | " 200 | \n",
186 | " 1 | \n",
187 | "
\n",
188 | " \n",
189 | "
\n",
190 | "
"
191 | ],
192 | "text/plain": [
193 | " Blood Sugar Level Diabetes\n",
194 | "0 190 0\n",
195 | "1 240 1\n",
196 | "2 300 1\n",
197 | "3 160 0\n",
198 | "4 200 1"
199 | ]
200 | },
201 | "execution_count": 33,
202 | "metadata": {},
203 | "output_type": "execute_result"
204 | }
205 | ],
206 | "source": [
207 | "dib.head()"
208 | ]
209 | },
210 | {
211 | "cell_type": "code",
212 | "execution_count": 34,
213 | "metadata": {
214 | "collapsed": true
215 | },
216 | "outputs": [],
217 | "source": [
218 | "# Putting feature variable to X\n",
219 | "X = dib['Blood Sugar Level']\n",
220 | "\n",
221 | "# Putting response variable to y\n",
222 | "y = dib['Diabetes']"
223 | ]
224 | },
225 | {
226 | "cell_type": "code",
227 | "execution_count": 36,
228 | "metadata": {},
229 | "outputs": [],
230 | "source": [
231 | "import statsmodels.api as sm"
232 | ]
233 | },
234 | {
235 | "cell_type": "code",
236 | "execution_count": 37,
237 | "metadata": {},
238 | "outputs": [
239 | {
240 | "data": {
241 | "text/html": [
242 | "\n",
243 | "Generalized Linear Model Regression Results\n",
244 | "\n",
245 | " Dep. Variable: | Diabetes | No. Observations: | 10 | \n",
246 | "
\n",
247 | "\n",
248 | " Model: | GLM | Df Residuals: | 8 | \n",
249 | "
\n",
250 | "\n",
251 | " Model Family: | Binomial | Df Model: | 1 | \n",
252 | "
\n",
253 | "\n",
254 | " Link Function: | logit | Scale: | 1.0 | \n",
255 | "
\n",
256 | "\n",
257 | " Method: | IRLS | Log-Likelihood: | -2.5838 | \n",
258 | "
\n",
259 | "\n",
260 | " Date: | Tue, 06 Mar 2018 | Deviance: | 5.1676 | \n",
261 | "
\n",
262 | "\n",
263 | " Time: | 00:56:36 | Pearson chi2: | 4.32 | \n",
264 | "
\n",
265 | "\n",
266 | " No. Iterations: | 7 | | | \n",
267 | "
\n",
268 | "
\n",
269 | "\n",
270 | "\n",
271 | " | coef | std err | z | P>|z| | [0.025 | 0.975] | \n",
272 | "
\n",
273 | "\n",
274 | " const | -13.5243 | 9.358 | -1.445 | 0.148 | -31.866 | 4.817 | \n",
275 | "
\n",
276 | "\n",
277 | " Blood Sugar Level | 0.0637 | 0.044 | 1.439 | 0.150 | -0.023 | 0.150 | \n",
278 | "
\n",
279 | "
"
280 | ],
281 | "text/plain": [
282 | "\n",
283 | "\"\"\"\n",
284 | " Generalized Linear Model Regression Results \n",
285 | "==============================================================================\n",
286 | "Dep. Variable: Diabetes No. Observations: 10\n",
287 | "Model: GLM Df Residuals: 8\n",
288 | "Model Family: Binomial Df Model: 1\n",
289 | "Link Function: logit Scale: 1.0\n",
290 | "Method: IRLS Log-Likelihood: -2.5838\n",
291 | "Date: Tue, 06 Mar 2018 Deviance: 5.1676\n",
292 | "Time: 00:56:36 Pearson chi2: 4.32\n",
293 | "No. Iterations: 7 \n",
294 | "=====================================================================================\n",
295 | " coef std err z P>|z| [0.025 0.975]\n",
296 | "-------------------------------------------------------------------------------------\n",
297 | "const -13.5243 9.358 -1.445 0.148 -31.866 4.817\n",
298 | "Blood Sugar Level 0.0637 0.044 1.439 0.150 -0.023 0.150\n",
299 | "=====================================================================================\n",
300 | "\"\"\""
301 | ]
302 | },
303 | "execution_count": 37,
304 | "metadata": {},
305 | "output_type": "execute_result"
306 | }
307 | ],
308 | "source": [
309 | "logm1 = sm.GLM(y,(sm.add_constant(X)), family = sm.families.Binomial())\n",
310 | "logm1.fit().summary()"
311 | ]
312 | },
313 | {
314 | "cell_type": "code",
315 | "execution_count": null,
316 | "metadata": {
317 | "collapsed": true
318 | },
319 | "outputs": [],
320 | "source": []
321 | }
322 | ],
323 | "metadata": {
324 | "kernelspec": {
325 | "display_name": "Python 3",
326 | "language": "python",
327 | "name": "python3"
328 | },
329 | "language_info": {
330 | "codemirror_mode": {
331 | "name": "ipython",
332 | "version": 3
333 | },
334 | "file_extension": ".py",
335 | "mimetype": "text/x-python",
336 | "name": "python",
337 | "nbconvert_exporter": "python",
338 | "pygments_lexer": "ipython3",
339 | "version": "3.6.3"
340 | }
341 | },
342 | "nbformat": 4,
343 | "nbformat_minor": 2
344 | }
345 |
--------------------------------------------------------------------------------
/Univariate Logistic Regression/init:
--------------------------------------------------------------------------------
1 |
2 |
--------------------------------------------------------------------------------