├── 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 | ![Screenshot (416)](https://user-images.githubusercontent.com/82654736/141272804-9d65d7b2-6903-4163-872f-3fcd5e7d37af.png) 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 | ![Screenshot (415)](https://user-images.githubusercontent.com/82654736/141272958-70588405-c53b-4674-a35e-1141bf00711e.png) 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 | ![Screenshot (417)](https://user-images.githubusercontent.com/82654736/141273158-2b6a4f18-7886-44dc-97e0-593e8d35002e.png) 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 | ![Screenshot (417)](https://user-images.githubusercontent.com/82654736/141273158-2b6a4f18-7886-44dc-97e0-593e8d35002e.png) 33 | 34 | 35 | #### Univariate Logistic Regression 36 | You will find the following files in the code folder of Univariate Logistic Regression 37 | ![Screenshot (418)](https://user-images.githubusercontent.com/82654736/141273314-300a97de-2f43-4e96-a66b-ed050085041b.png) 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 | " \n", 69 | " \n", 70 | " \n", 71 | " \n", 72 | " \n", 73 | " \n", 74 | " \n", 75 | " \n", 76 | " \n", 77 | " \n", 78 | " \n", 79 | " \n", 80 | " \n", 81 | " \n", 82 | " \n", 83 | " \n", 84 | " \n", 85 | " \n", 86 | " \n", 87 | " \n", 88 | " \n", 89 | " \n", 90 | " \n", 91 | " \n", 92 | " \n", 93 | " \n", 94 | " \n", 95 | " \n", 96 | " \n", 97 | " \n", 98 | " \n", 99 | "
Blood Sugar LevelDiabetes
0190No
1240Yes
2300Yes
3160No
4200Yes
\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 | " \n", 159 | " \n", 160 | " \n", 161 | " \n", 162 | " \n", 163 | " \n", 164 | " \n", 165 | " \n", 166 | " \n", 167 | " \n", 168 | " \n", 169 | " \n", 170 | " \n", 171 | " \n", 172 | " \n", 173 | " \n", 174 | " \n", 175 | " \n", 176 | " \n", 177 | " \n", 178 | " \n", 179 | " \n", 180 | " \n", 181 | " \n", 182 | " \n", 183 | " \n", 184 | " \n", 185 | " \n", 186 | " \n", 187 | " \n", 188 | " \n", 189 | "
Blood Sugar LevelDiabetes
01900
12401
23001
31600
42001
\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 | "\n", 244 | "\n", 245 | " \n", 246 | "\n", 247 | "\n", 248 | " \n", 249 | "\n", 250 | "\n", 251 | " \n", 252 | "\n", 253 | "\n", 254 | " \n", 255 | "\n", 256 | "\n", 257 | " \n", 258 | "\n", 259 | "\n", 260 | " \n", 261 | "\n", 262 | "\n", 263 | " \n", 264 | "\n", 265 | "\n", 266 | " \n", 267 | "\n", 268 | "
Generalized Linear Model Regression Results
Dep. Variable: Diabetes No. Observations: 10
Model: GLM Df Residuals: 8
Model Family: Binomial Df Model: 1
Link Function: logit Scale: 1.0
Method: IRLS Log-Likelihood: -2.5838
Date: Tue, 06 Mar 2018 Deviance: 5.1676
Time: 00:56:36 Pearson chi2: 4.32
No. Iterations: 7
\n", 269 | "\n", 270 | "\n", 271 | " \n", 272 | "\n", 273 | "\n", 274 | " \n", 275 | "\n", 276 | "\n", 277 | " \n", 278 | "\n", 279 | "
coef std err z P>|z| [0.025 0.975]
const -13.5243 9.358 -1.445 0.148 -31.866 4.817
Blood Sugar Level 0.0637 0.044 1.439 0.150 -0.023 0.150
" 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 | --------------------------------------------------------------------------------