SagarManchekar commited on
Commit
5c3950b
·
1 Parent(s): 75004a2

Upload 2 files

Browse files
Files changed (2) hide show
  1. Social_Network_Ads.csv +401 -0
  2. logistic_regression.py +79 -0
Social_Network_Ads.csv ADDED
@@ -0,0 +1,401 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Age,EstimatedSalary,Purchased
2
+ 19,19000,0
3
+ 35,20000,0
4
+ 26,43000,0
5
+ 27,57000,0
6
+ 19,76000,0
7
+ 27,58000,0
8
+ 27,84000,0
9
+ 32,150000,1
10
+ 25,33000,0
11
+ 35,65000,0
12
+ 26,80000,0
13
+ 26,52000,0
14
+ 20,86000,0
15
+ 32,18000,0
16
+ 18,82000,0
17
+ 29,80000,0
18
+ 47,25000,1
19
+ 45,26000,1
20
+ 46,28000,1
21
+ 48,29000,1
22
+ 45,22000,1
23
+ 47,49000,1
24
+ 48,41000,1
25
+ 45,22000,1
26
+ 46,23000,1
27
+ 47,20000,1
28
+ 49,28000,1
29
+ 47,30000,1
30
+ 29,43000,0
31
+ 31,18000,0
32
+ 31,74000,0
33
+ 27,137000,1
34
+ 21,16000,0
35
+ 28,44000,0
36
+ 27,90000,0
37
+ 35,27000,0
38
+ 33,28000,0
39
+ 30,49000,0
40
+ 26,72000,0
41
+ 27,31000,0
42
+ 27,17000,0
43
+ 33,51000,0
44
+ 35,108000,0
45
+ 30,15000,0
46
+ 28,84000,0
47
+ 23,20000,0
48
+ 25,79000,0
49
+ 27,54000,0
50
+ 30,135000,1
51
+ 31,89000,0
52
+ 24,32000,0
53
+ 18,44000,0
54
+ 29,83000,0
55
+ 35,23000,0
56
+ 27,58000,0
57
+ 24,55000,0
58
+ 23,48000,0
59
+ 28,79000,0
60
+ 22,18000,0
61
+ 32,117000,0
62
+ 27,20000,0
63
+ 25,87000,0
64
+ 23,66000,0
65
+ 32,120000,1
66
+ 59,83000,0
67
+ 24,58000,0
68
+ 24,19000,0
69
+ 23,82000,0
70
+ 22,63000,0
71
+ 31,68000,0
72
+ 25,80000,0
73
+ 24,27000,0
74
+ 20,23000,0
75
+ 33,113000,0
76
+ 32,18000,0
77
+ 34,112000,1
78
+ 18,52000,0
79
+ 22,27000,0
80
+ 28,87000,0
81
+ 26,17000,0
82
+ 30,80000,0
83
+ 39,42000,0
84
+ 20,49000,0
85
+ 35,88000,0
86
+ 30,62000,0
87
+ 31,118000,1
88
+ 24,55000,0
89
+ 28,85000,0
90
+ 26,81000,0
91
+ 35,50000,0
92
+ 22,81000,0
93
+ 30,116000,0
94
+ 26,15000,0
95
+ 29,28000,0
96
+ 29,83000,0
97
+ 35,44000,0
98
+ 35,25000,0
99
+ 28,123000,1
100
+ 35,73000,0
101
+ 28,37000,0
102
+ 27,88000,0
103
+ 28,59000,0
104
+ 32,86000,0
105
+ 33,149000,1
106
+ 19,21000,0
107
+ 21,72000,0
108
+ 26,35000,0
109
+ 27,89000,0
110
+ 26,86000,0
111
+ 38,80000,0
112
+ 39,71000,0
113
+ 37,71000,0
114
+ 38,61000,0
115
+ 37,55000,0
116
+ 42,80000,0
117
+ 40,57000,0
118
+ 35,75000,0
119
+ 36,52000,0
120
+ 40,59000,0
121
+ 41,59000,0
122
+ 36,75000,0
123
+ 37,72000,0
124
+ 40,75000,0
125
+ 35,53000,0
126
+ 41,51000,0
127
+ 39,61000,0
128
+ 42,65000,0
129
+ 26,32000,0
130
+ 30,17000,0
131
+ 26,84000,0
132
+ 31,58000,0
133
+ 33,31000,0
134
+ 30,87000,0
135
+ 21,68000,0
136
+ 28,55000,0
137
+ 23,63000,0
138
+ 20,82000,0
139
+ 30,107000,1
140
+ 28,59000,0
141
+ 19,25000,0
142
+ 19,85000,0
143
+ 18,68000,0
144
+ 35,59000,0
145
+ 30,89000,0
146
+ 34,25000,0
147
+ 24,89000,0
148
+ 27,96000,1
149
+ 41,30000,0
150
+ 29,61000,0
151
+ 20,74000,0
152
+ 26,15000,0
153
+ 41,45000,0
154
+ 31,76000,0
155
+ 36,50000,0
156
+ 40,47000,0
157
+ 31,15000,0
158
+ 46,59000,0
159
+ 29,75000,0
160
+ 26,30000,0
161
+ 32,135000,1
162
+ 32,100000,1
163
+ 25,90000,0
164
+ 37,33000,0
165
+ 35,38000,0
166
+ 33,69000,0
167
+ 18,86000,0
168
+ 22,55000,0
169
+ 35,71000,0
170
+ 29,148000,1
171
+ 29,47000,0
172
+ 21,88000,0
173
+ 34,115000,0
174
+ 26,118000,0
175
+ 34,43000,0
176
+ 34,72000,0
177
+ 23,28000,0
178
+ 35,47000,0
179
+ 25,22000,0
180
+ 24,23000,0
181
+ 31,34000,0
182
+ 26,16000,0
183
+ 31,71000,0
184
+ 32,117000,1
185
+ 33,43000,0
186
+ 33,60000,0
187
+ 31,66000,0
188
+ 20,82000,0
189
+ 33,41000,0
190
+ 35,72000,0
191
+ 28,32000,0
192
+ 24,84000,0
193
+ 19,26000,0
194
+ 29,43000,0
195
+ 19,70000,0
196
+ 28,89000,0
197
+ 34,43000,0
198
+ 30,79000,0
199
+ 20,36000,0
200
+ 26,80000,0
201
+ 35,22000,0
202
+ 35,39000,0
203
+ 49,74000,0
204
+ 39,134000,1
205
+ 41,71000,0
206
+ 58,101000,1
207
+ 47,47000,0
208
+ 55,130000,1
209
+ 52,114000,0
210
+ 40,142000,1
211
+ 46,22000,0
212
+ 48,96000,1
213
+ 52,150000,1
214
+ 59,42000,0
215
+ 35,58000,0
216
+ 47,43000,0
217
+ 60,108000,1
218
+ 49,65000,0
219
+ 40,78000,0
220
+ 46,96000,0
221
+ 59,143000,1
222
+ 41,80000,0
223
+ 35,91000,1
224
+ 37,144000,1
225
+ 60,102000,1
226
+ 35,60000,0
227
+ 37,53000,0
228
+ 36,126000,1
229
+ 56,133000,1
230
+ 40,72000,0
231
+ 42,80000,1
232
+ 35,147000,1
233
+ 39,42000,0
234
+ 40,107000,1
235
+ 49,86000,1
236
+ 38,112000,0
237
+ 46,79000,1
238
+ 40,57000,0
239
+ 37,80000,0
240
+ 46,82000,0
241
+ 53,143000,1
242
+ 42,149000,1
243
+ 38,59000,0
244
+ 50,88000,1
245
+ 56,104000,1
246
+ 41,72000,0
247
+ 51,146000,1
248
+ 35,50000,0
249
+ 57,122000,1
250
+ 41,52000,0
251
+ 35,97000,1
252
+ 44,39000,0
253
+ 37,52000,0
254
+ 48,134000,1
255
+ 37,146000,1
256
+ 50,44000,0
257
+ 52,90000,1
258
+ 41,72000,0
259
+ 40,57000,0
260
+ 58,95000,1
261
+ 45,131000,1
262
+ 35,77000,0
263
+ 36,144000,1
264
+ 55,125000,1
265
+ 35,72000,0
266
+ 48,90000,1
267
+ 42,108000,1
268
+ 40,75000,0
269
+ 37,74000,0
270
+ 47,144000,1
271
+ 40,61000,0
272
+ 43,133000,0
273
+ 59,76000,1
274
+ 60,42000,1
275
+ 39,106000,1
276
+ 57,26000,1
277
+ 57,74000,1
278
+ 38,71000,0
279
+ 49,88000,1
280
+ 52,38000,1
281
+ 50,36000,1
282
+ 59,88000,1
283
+ 35,61000,0
284
+ 37,70000,1
285
+ 52,21000,1
286
+ 48,141000,0
287
+ 37,93000,1
288
+ 37,62000,0
289
+ 48,138000,1
290
+ 41,79000,0
291
+ 37,78000,1
292
+ 39,134000,1
293
+ 49,89000,1
294
+ 55,39000,1
295
+ 37,77000,0
296
+ 35,57000,0
297
+ 36,63000,0
298
+ 42,73000,1
299
+ 43,112000,1
300
+ 45,79000,0
301
+ 46,117000,1
302
+ 58,38000,1
303
+ 48,74000,1
304
+ 37,137000,1
305
+ 37,79000,1
306
+ 40,60000,0
307
+ 42,54000,0
308
+ 51,134000,0
309
+ 47,113000,1
310
+ 36,125000,1
311
+ 38,50000,0
312
+ 42,70000,0
313
+ 39,96000,1
314
+ 38,50000,0
315
+ 49,141000,1
316
+ 39,79000,0
317
+ 39,75000,1
318
+ 54,104000,1
319
+ 35,55000,0
320
+ 45,32000,1
321
+ 36,60000,0
322
+ 52,138000,1
323
+ 53,82000,1
324
+ 41,52000,0
325
+ 48,30000,1
326
+ 48,131000,1
327
+ 41,60000,0
328
+ 41,72000,0
329
+ 42,75000,0
330
+ 36,118000,1
331
+ 47,107000,1
332
+ 38,51000,0
333
+ 48,119000,1
334
+ 42,65000,0
335
+ 40,65000,0
336
+ 57,60000,1
337
+ 36,54000,0
338
+ 58,144000,1
339
+ 35,79000,0
340
+ 38,55000,0
341
+ 39,122000,1
342
+ 53,104000,1
343
+ 35,75000,0
344
+ 38,65000,0
345
+ 47,51000,1
346
+ 47,105000,1
347
+ 41,63000,0
348
+ 53,72000,1
349
+ 54,108000,1
350
+ 39,77000,0
351
+ 38,61000,0
352
+ 38,113000,1
353
+ 37,75000,0
354
+ 42,90000,1
355
+ 37,57000,0
356
+ 36,99000,1
357
+ 60,34000,1
358
+ 54,70000,1
359
+ 41,72000,0
360
+ 40,71000,1
361
+ 42,54000,0
362
+ 43,129000,1
363
+ 53,34000,1
364
+ 47,50000,1
365
+ 42,79000,0
366
+ 42,104000,1
367
+ 59,29000,1
368
+ 58,47000,1
369
+ 46,88000,1
370
+ 38,71000,0
371
+ 54,26000,1
372
+ 60,46000,1
373
+ 60,83000,1
374
+ 39,73000,0
375
+ 59,130000,1
376
+ 37,80000,0
377
+ 46,32000,1
378
+ 46,74000,0
379
+ 42,53000,0
380
+ 41,87000,1
381
+ 58,23000,1
382
+ 42,64000,0
383
+ 48,33000,1
384
+ 44,139000,1
385
+ 49,28000,1
386
+ 57,33000,1
387
+ 56,60000,1
388
+ 49,39000,1
389
+ 39,71000,0
390
+ 47,34000,1
391
+ 48,35000,1
392
+ 48,33000,1
393
+ 47,23000,1
394
+ 45,45000,1
395
+ 60,42000,1
396
+ 39,59000,0
397
+ 46,41000,1
398
+ 51,23000,1
399
+ 50,20000,1
400
+ 36,33000,0
401
+ 49,36000,1
logistic_regression.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Logistic Regression
2
+
3
+ # Importing the libraries
4
+ import numpy as np
5
+ import matplotlib.pyplot as plt
6
+ import pandas as pd
7
+
8
+ # Importing the dataset
9
+ dataset = pd.read_csv('Social_Network_Ads.csv')
10
+ X = dataset.iloc[:, :-1].values
11
+ y = dataset.iloc[:, -1].values
12
+
13
+ # Splitting the dataset into the Training set and Test set
14
+ from sklearn.model_selection import train_test_split
15
+ X_train, X_test, y_train, y_test = train_test_split(X, y, test_size = 0.25, random_state = 0)
16
+ print(X_train)
17
+ print(y_train)
18
+ print(X_test)
19
+ print(y_test)
20
+
21
+ # Feature Scaling
22
+ from sklearn.preprocessing import StandardScaler
23
+ sc = StandardScaler()
24
+ X_train = sc.fit_transform(X_train)
25
+ X_test = sc.transform(X_test)
26
+ print(X_train)
27
+ print(X_test)
28
+
29
+ # Training the Logistic Regression model on the Training set
30
+ from sklearn.linear_model import LogisticRegression
31
+ classifier = LogisticRegression(random_state = 0)
32
+ classifier.fit(X_train, y_train)
33
+
34
+ # Predicting a new result
35
+ print(classifier.predict(sc.transform([[30,87000]])))
36
+
37
+ # Predicting the Test set results
38
+ y_pred = classifier.predict(X_test)
39
+ print(np.concatenate((y_pred.reshape(len(y_pred),1), y_test.reshape(len(y_test),1)),1))
40
+
41
+ # Making the Confusion Matrix
42
+ from sklearn.metrics import confusion_matrix, accuracy_score
43
+ cm = confusion_matrix(y_test, y_pred)
44
+ print(cm)
45
+ accuracy_score(y_test, y_pred)
46
+
47
+ # Visualising the Training set results
48
+ from matplotlib.colors import ListedColormap
49
+ X_set, y_set = sc.inverse_transform(X_train), y_train
50
+ X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),
51
+ np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))
52
+ plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),
53
+ alpha = 0.75, cmap = ListedColormap(('red', 'green')))
54
+ plt.xlim(X1.min(), X1.max())
55
+ plt.ylim(X2.min(), X2.max())
56
+ for i, j in enumerate(np.unique(y_set)):
57
+ plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)
58
+ plt.title('Logistic Regression (Training set)')
59
+ plt.xlabel('Age')
60
+ plt.ylabel('Estimated Salary')
61
+ plt.legend()
62
+ plt.show()
63
+
64
+ # Visualising the Test set results
65
+ from matplotlib.colors import ListedColormap
66
+ X_set, y_set = sc.inverse_transform(X_test), y_test
67
+ X1, X2 = np.meshgrid(np.arange(start = X_set[:, 0].min() - 10, stop = X_set[:, 0].max() + 10, step = 0.25),
68
+ np.arange(start = X_set[:, 1].min() - 1000, stop = X_set[:, 1].max() + 1000, step = 0.25))
69
+ plt.contourf(X1, X2, classifier.predict(sc.transform(np.array([X1.ravel(), X2.ravel()]).T)).reshape(X1.shape),
70
+ alpha = 0.75, cmap = ListedColormap(('red', 'green')))
71
+ plt.xlim(X1.min(), X1.max())
72
+ plt.ylim(X2.min(), X2.max())
73
+ for i, j in enumerate(np.unique(y_set)):
74
+ plt.scatter(X_set[y_set == j, 0], X_set[y_set == j, 1], c = ListedColormap(('red', 'green'))(i), label = j)
75
+ plt.title('Logistic Regression (Test set)')
76
+ plt.xlabel('Age')
77
+ plt.ylabel('Estimated Salary')
78
+ plt.legend()
79
+ plt.show()