-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathLogisticRegression.html
524 lines (486 loc) · 49 KB
/
LogisticRegression.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="mobile-web-app-capable" content="yes">
<title>
Logistic Regression - HackMD
</title>
<link rel="icon" type="image/png" href="https://hackmd.io/favicon.png">
<link rel="apple-touch-icon" href="https://hackmd.io/apple-touch-icon.png">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha256-916EbMg70RQy9LHiGkXzG8hSg9EdNy97GazNG/aiY1w=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" integrity="sha256-eZrrJcwDc/3uDhsdt61sL2oOBY362qM3lon1gyExkL0=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionicons/2.0.1/css/ionicons.min.css" integrity="sha256-3iu9jgsy9TpTwXKb7bNQzqWekRX7pPK+2OLj3R922fo=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/octicons/3.5.0/octicons.min.css" integrity="sha256-QiWfLIsCT02Sdwkogf6YMiQlj4NE84MKkzEMkZnMGdg=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/prism/1.5.1/themes/prism.min.css" integrity="sha256-vtR0hSWRc3Tb26iuN2oZHt3KRUomwTufNIf5/4oeCyg=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/9.7.0/styles/github-gist.min.css" integrity="sha256-tAflq+ymku3Khs+I/WcAneIlafYgDiOQ9stIHH985Wo=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/emojify.js/1.1.0/css/basic/emojify.min.css" integrity="sha256-UOrvMOsSDSrW6szVLe8ZDZezBxh5IoIfgTwdNDgTjiU=" crossorigin="anonymous" />
<style>
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:400,400italic,600,600italic,300italic,300|Source+Serif+Pro|Source+Code+Pro:400,300,500&subset=latin,latin-ext);.markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica,Arial,sans-serif;font-size:16px;line-height:1.5;word-wrap:break-word}.markdown-body:after,.markdown-body:before{display:table;content:""}.markdown-body:after{clear:both}.markdown-body>:first-child{margin-top:0!important}.markdown-body>:last-child{margin-bottom:0!important}.markdown-body a:not([href]){color:inherit;text-decoration:none}.markdown-body .absent{color:#c00}.markdown-body .anchor{float:left;padding-right:4px;margin-left:-20px;line-height:1}.markdown-body .anchor:focus{outline:none}.markdown-body blockquote,.markdown-body dl,.markdown-body ol,.markdown-body p,.markdown-body pre,.markdown-body table,.markdown-body ul{margin-top:0;margin-bottom:16px}.markdown-body hr{height:.25em;padding:0;margin:24px 0;background-color:#e7e7e7;border:0}.markdown-body blockquote{padding:0 1em;color:#777;border-left:.25em solid #ddd}.markdown-body blockquote>:first-child{margin-top:0}.markdown-body blockquote>:last-child{margin-bottom:0}.markdown-body .loweralpha{list-style-type:lower-alpha}.markdown-body h1,.markdown-body h2,.markdown-body h3,.markdown-body h4,.markdown-body h5,.markdown-body h6{margin-top:24px;margin-bottom:16px;font-weight:600;line-height:1.25}.markdown-body h1 .octicon-link,.markdown-body h2 .octicon-link,.markdown-body h3 .octicon-link,.markdown-body h4 .octicon-link,.markdown-body h5 .octicon-link,.markdown-body h6 .octicon-link{color:#000;vertical-align:middle;visibility:hidden}.markdown-body h1:hover .anchor,.markdown-body h2:hover .anchor,.markdown-body h3:hover .anchor,.markdown-body h4:hover .anchor,.markdown-body h5:hover .anchor,.markdown-body h6:hover .anchor{text-decoration:none}.markdown-body h1:hover .anchor .octicon-link,.markdown-body h2:hover .anchor .octicon-link,.markdown-body h3:hover .anchor .octicon-link,.markdown-body h4:hover .anchor .octicon-link,.markdown-body h5:hover .anchor .octicon-link,.markdown-body h6:hover .anchor .octicon-link{visibility:visible}.markdown-body h1 code,.markdown-body h1 tt,.markdown-body h2 code,.markdown-body h2 tt,.markdown-body h3 code,.markdown-body h3 tt,.markdown-body h4 code,.markdown-body h4 tt,.markdown-body h5 code,.markdown-body h5 tt,.markdown-body h6 code,.markdown-body h6 tt{font-size:inherit}.markdown-body h1{font-size:2em}.markdown-body h1,.markdown-body h2{padding-bottom:.3em;border-bottom:1px solid #eee}.markdown-body h2{font-size:1.5em}.markdown-body h3{font-size:1.25em}.markdown-body h4{font-size:1em}.markdown-body h5{font-size:.875em}.markdown-body h6{font-size:.85em;color:#777}.markdown-body ol,.markdown-body ul{padding-left:2em}.markdown-body ol.no-list,.markdown-body ul.no-list{padding:0;list-style-type:none}.markdown-body ol ol,.markdown-body ol ul,.markdown-body ul ol,.markdown-body ul ul{margin-top:0;margin-bottom:0}.markdown-body li>p{margin-top:16px}.markdown-body li+li{margin-top:.25em}.markdown-body dl{padding:0}.markdown-body dl dt{padding:0;margin-top:16px;font-size:1em;font-style:italic;font-weight:700}.markdown-body dl dd{padding:0 16px;margin-bottom:16px}.markdown-body table{display:block;width:100%;overflow:auto;word-break:normal;word-break:keep-all}.markdown-body table th{font-weight:700}.markdown-body table td,.markdown-body table th{padding:6px 13px;border:1px solid #ddd}.markdown-body table tr{background-color:#fff;border-top:1px solid #ccc}.markdown-body table tr:nth-child(2n){background-color:#f8f8f8}.markdown-body img{max-width:100%;box-sizing:content-box;background-color:#fff}.markdown-body img[align=right]{padding-left:20px}.markdown-body img[align=left]{padding-right:20px}.markdown-body .emoji{max-width:none;vertical-align:text-top;background-color:transparent}.markdown-body span.frame{display:block;overflow:hidden}.markdown-body span.frame>span{display:block;float:left;width:auto;padding:7px;margin:13px 0 0;overflow:hidden;border:1px solid #ddd}.markdown-body span.frame span img{display:block;float:left}.markdown-body span.frame span span{display:block;padding:5px 0 0;clear:both;color:#333}.markdown-body span.align-center{display:block;overflow:hidden;clear:both}.markdown-body span.align-center>span{display:block;margin:13px auto 0;overflow:hidden;text-align:center}.markdown-body span.align-center span img{margin:0 auto;text-align:center}.markdown-body span.align-right{display:block;overflow:hidden;clear:both}.markdown-body span.align-right>span{display:block;margin:13px 0 0;overflow:hidden;text-align:right}.markdown-body span.align-right span img{margin:0;text-align:right}.markdown-body span.float-left{display:block;float:left;margin-right:13px;overflow:hidden}.markdown-body span.float-left span{margin:13px 0 0}.markdown-body span.float-right{display:block;float:right;margin-left:13px;overflow:hidden}.markdown-body span.float-right>span{display:block;margin:13px auto 0;overflow:hidden;text-align:right}.markdown-body code,.markdown-body tt{padding:0;padding-top:.2em;padding-bottom:.2em;margin:0;font-size:85%;background-color:rgba(0,0,0,.04);border-radius:3px}.markdown-body code:after,.markdown-body code:before,.markdown-body tt:after,.markdown-body tt:before{letter-spacing:-.2em;content:"\A0"}.markdown-body code br,.markdown-body tt br{display:none}.markdown-body del code{text-decoration:inherit}.markdown-body pre{word-wrap:normal}.markdown-body pre>code{padding:0;margin:0;font-size:100%;word-break:normal;white-space:pre;background:transparent;border:0}.markdown-body .highlight{margin-bottom:16px}.markdown-body .highlight pre{margin-bottom:0;word-break:normal}.markdown-body .highlight pre,.markdown-body pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f7f7f7;border-radius:3px}.markdown-body pre code,.markdown-body pre tt{display:inline;max-width:auto;padding:0;margin:0;overflow:visible;line-height:inherit;word-wrap:normal;background-color:transparent;border:0}.markdown-body pre code:after,.markdown-body pre code:before,.markdown-body pre tt:after,.markdown-body pre tt:before{content:normal}.markdown-body .csv-data td,.markdown-body .csv-data th{padding:5px;overflow:hidden;font-size:12px;line-height:1;text-align:left;white-space:nowrap}.markdown-body .csv-data .blob-line-num{padding:10px 8px 9px;text-align:right;background:#fff;border:0}.markdown-body .csv-data tr{border-top:0}.markdown-body .csv-data th{font-weight:700;background:#f8f8f8;border-top:0}.markdown-body kbd{display:inline-block;padding:3px 5px;font-size:11px;line-height:10px;color:#555;vertical-align:middle;background-color:#fcfcfc;border:1px solid #ccc;border-bottom-color:#bbb;border-radius:3px;box-shadow:inset 0 -1px 0 #bbb}.news .alert .markdown-body blockquote{padding:0 0 0 40px;border:0 none}.activity-tab .news .alert .commits,.activity-tab .news .markdown-body blockquote{padding-left:0}.task-list-item{list-style-type:none}.task-list-item label{font-weight:400}.task-list-item.enabled label{cursor:pointer}.task-list-item+.task-list-item{margin-top:3px}.task-list-item-checkbox{float:left;margin:.31em 0 .2em -1.3em!important;vertical-align:middle;cursor:default!important}.markdown-body{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Helvetica,Arial,sans-serif;padding-top:40px;padding-bottom:40px;max-width:758px;overflow:visible!important}.markdown-body pre{border:inherit!important}.markdown-body code{color:inherit!important}.markdown-body pre code .wrapper{display:-moz-inline-flex;display:-ms-inline-flex;display:-o-inline-flex;display:inline-flex}.markdown-body pre code .gutter{float:left;overflow:hidden;-webkit-user-select:none;user-select:none}.markdown-body pre code .gutter.linenumber{text-align:right;position:relative;display:inline-block;cursor:default;z-index:4;padding:0 8px 0 0;min-width:20px;box-sizing:content-box;color:#afafaf!important;border-right:3px solid #6ce26c!important}.markdown-body pre code .gutter.linenumber>span:before{content:attr(data-linenumber)}.markdown-body pre code .code{float:left;margin:0 0 0 16px}.markdown-body .gist .line-numbers{border-left:none;border-top:none;border-bottom:none}.markdown-body .gist .line-data{border:none}.markdown-body .gist table{border-spacing:0;border-collapse:inherit!important}.markdown-body code[data-gist-id]{background:none;padding:0}.markdown-body code[data-gist-id]:after,.markdown-body code[data-gist-id]:before{content:""}.markdown-body code[data-gist-id] .blob-num{border:unset}.markdown-body code[data-gist-id] table{overflow:unset;margin-bottom:unset}.markdown-body code[data-gist-id] table tr{background:unset}.markdown-body[dir=rtl] pre{direction:ltr}.markdown-body[dir=rtl] code{direction:ltr;unicode-bidi:embed}.markdown-body .alert>p{margin-bottom:0}.markdown-body pre.abc,.markdown-body pre.flow-chart,.markdown-body pre.graphviz,.markdown-body pre.mermaid,.markdown-body pre.sequence-diagram{text-align:center;background-color:inherit;border-radius:0;white-space:inherit}.markdown-body pre.abc>code,.markdown-body pre.flow-chart>code,.markdown-body pre.graphviz>code,.markdown-body pre.mermaid>code,.markdown-body pre.sequence-diagram>code{text-align:left}.markdown-body pre.abc>svg,.markdown-body pre.flow-chart>svg,.markdown-body pre.graphviz>svg,.markdown-body pre.mermaid>svg,.markdown-body pre.sequence-diagram>svg{max-width:100%;height:100%}.markdown-body pre>code.wrap{white-space:pre-wrap;white-space:-moz-pre-wrap;white-space:-pre-wrap;white-space:-o-pre-wrap;word-wrap:break-word}.markdown-body .alert>p,.markdown-body .alert>ul{margin-bottom:0}.vimeo,.youtube{cursor:pointer;display:table;text-align:center;background-position:50%;background-repeat:no-repeat;background-size:contain;background-color:#000;overflow:hidden}.vimeo,.youtube{position:relative;width:100%}.youtube{padding-bottom:56.25%}.vimeo img{width:100%;object-fit:contain;z-index:0}.youtube img{object-fit:cover;z-index:0}.vimeo iframe,.youtube iframe,.youtube img{width:100%;height:100%;position:absolute;top:0;left:0}.vimeo iframe,.youtube iframe{vertical-align:middle;z-index:1}.vimeo .icon,.youtube .icon{position:absolute;height:auto;width:auto;top:50%;left:50%;transform:translate(-50%,-50%);color:#fff;opacity:.3;transition:opacity .2s;z-index:0}.vimeo:hover .icon,.youtube:hover .icon{opacity:.6;transition:opacity .2s}.slideshare .inner,.speakerdeck .inner{position:relative;width:100%}.slideshare .inner iframe,.speakerdeck .inner iframe{position:absolute;top:0;bottom:0;left:0;right:0;width:100%;height:100%}.MJX_Assistive_MathML{display:none}.ui-infobar{position:relative;z-index:2;max-width:758px;margin-top:25px;margin-bottom:-25px;color:#777}.ui-toc{position:fixed;bottom:20px;z-index:10000}.ui-toc-label{opacity:.3;background-color:#ccc;border:none;transition:opacity .2s}.ui-toc .open .ui-toc-label{opacity:1;color:#fff;transition:opacity .2s}.ui-toc-label:focus{opacity:.3;background-color:#ccc;color:#000}.ui-toc-label:hover{opacity:1;background-color:#ccc;transition:opacity .2s}.ui-toc-dropdown{margin-top:23px;margin-bottom:20px;padding-left:10px;padding-right:10px;max-width:45vw;width:25vw;max-height:70vh;overflow:auto;text-align:inherit}.ui-toc-dropdown>.toc{max-height:calc(70vh - 100px);overflow:auto}.ui-toc-dropdown[dir=rtl] .nav{padding-right:0;letter-spacing:.0029em}.ui-toc-dropdown a{overflow:hidden;text-overflow:ellipsis;white-space:pre}.ui-toc-dropdown .nav>li>a{display:block;padding:4px 20px;font-size:13px;font-weight:500;color:#767676}.ui-toc-dropdown .nav>li:first-child:last-child > ul,.ui-toc-dropdown .toc.expand ul{display:block}.ui-toc-dropdown .nav>li>a:focus,.ui-toc-dropdown .nav>li>a:hover{padding-left:19px;color:#000;text-decoration:none;background-color:transparent;border-left:1px solid #000}.ui-toc-dropdown[dir=rtl] .nav>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav>li>a:hover{padding-right:19px;border-left:none;border-right:1px solid #000}.ui-toc-dropdown .nav>.active:focus>a,.ui-toc-dropdown .nav>.active:hover>a,.ui-toc-dropdown .nav>.active>a{padding-left:18px;font-weight:700;color:#000;background-color:transparent;border-left:2px solid #000}.ui-toc-dropdown[dir=rtl] .nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav>.active>a{padding-right:18px;border-left:none;border-right:2px solid #000}.ui-toc-dropdown .nav .nav{display:none;padding-bottom:10px}.ui-toc-dropdown .nav>.active>ul{display:block}.ui-toc-dropdown .nav .nav>li>a{padding-top:1px;padding-bottom:1px;padding-left:30px;font-size:12px;font-weight:400}.ui-toc-dropdown[dir=rtl] .nav .nav>li>a{padding-right:30px}.ui-toc-dropdown .nav .nav>li>ul>li>a{padding-top:1px;padding-bottom:1px;padding-left:40px;font-size:12px;font-weight:400}.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a{padding-right:40px}.ui-toc-dropdown .nav .nav>li>a:focus,.ui-toc-dropdown .nav .nav>li>a:hover{padding-left:29px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav .nav>li>a:hover{padding-right:29px}.ui-toc-dropdown .nav .nav>li>ul>li>a:focus,.ui-toc-dropdown .nav .nav>li>ul>li>a:hover{padding-left:39px}.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a:focus,.ui-toc-dropdown[dir=rtl] .nav .nav>li>ul>li>a:hover{padding-right:39px}.ui-toc-dropdown .nav .nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>a{padding-left:28px;font-weight:500}.ui-toc-dropdown[dir=rtl] .nav .nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>a{padding-right:28px}.ui-toc-dropdown .nav .nav>.active>.nav>.active:focus>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active:hover>a,.ui-toc-dropdown .nav .nav>.active>.nav>.active>a{padding-left:38px;font-weight:500}.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active:focus>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active:hover>a,.ui-toc-dropdown[dir=rtl] .nav .nav>.active>.nav>.active>a{padding-right:38px}.markdown-body[lang^=ja]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Helvetica,Arial,Hiragino Kaku Gothic Pro,\\30D2\30E9\30AE\30CE\89D2\30B4 Pro W3,Osaka,Meiryo,\\30E1\30A4\30EA\30AA,MS Gothic,"\FF2D\FF33 \30B4\30B7\30C3\30AF",sans-serif}.ui-toc-dropdown[lang^=ja]{font-family:Source Sans Pro,Helvetica,Arial,Meiryo UI,MS PGothic,"\FF2D\FF33 \FF30\30B4\30B7\30C3\30AF",sans-serif}.markdown-body[lang=zh-tw]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Helvetica,Arial,PingFang TC,Microsoft JhengHei,\\5FAE\8EDF\6B63\9ED1,sans-serif}.ui-toc-dropdown[lang=zh-tw]{font-family:Source Sans Pro,Helvetica,Arial,Microsoft JhengHei UI,\\5FAE\8EDF\6B63\9ED1UI,sans-serif}.markdown-body[lang=zh-cn]{font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Helvetica Neue,Helvetica,Arial,PingFang SC,Microsoft YaHei,\\5FAE\8F6F\96C5\9ED1,sans-serif}.ui-toc-dropdown[lang=zh-cn]{font-family:Source Sans Pro,Helvetica,Arial,Microsoft YaHei UI,\\5FAE\8F6F\96C5\9ED1UI,sans-serif}.ui-affix-toc{position:fixed;top:0;max-width:15vw;max-height:70vh;overflow:auto}.back-to-top,.expand-toggle,.go-to-bottom{display:block;padding:4px 10px;margin-top:10px;margin-left:10px;font-size:12px;font-weight:500;color:#999}.back-to-top:focus,.back-to-top:hover,.expand-toggle:focus,.expand-toggle:hover,.go-to-bottom:focus,.go-to-bottom:hover{color:#563d7c;text-decoration:none}.back-to-top,.go-to-bottom{margin-top:0}.ui-user-icon{width:20px;height:20px;display:block;border-radius:3px;margin-top:2px;margin-bottom:2px;margin-right:5px;background-position:50%;background-repeat:no-repeat;background-size:contain}.ui-user-icon.small{width:18px;height:18px;display:inline-block;vertical-align:middle;margin:0 0 .2em}small span{line-height:22px}small .dropdown{display:inline-block}small .dropdown a:focus,small .dropdown a:hover{text-decoration:none}.unselectable{-moz-user-select:none;-webkit-user-select:none;-o-user-select:none;user-select:none}@media print{blockquote,div,img,pre,table{page-break-inside:avoid!important}a[href]:after{font-size:12px!important}}.markdown-body.slides{position:relative;z-index:1;color:#222}.markdown-body.slides:before{content:"";display:block;position:absolute;top:0;left:0;right:0;bottom:0;z-index:-1;background-color:currentColor;box-shadow:0 0 0 50vw}.markdown-body.slides section[data-markdown]{position:relative;margin-bottom:1.5em;background-color:#fff;text-align:center}.markdown-body.slides section[data-markdown] code{text-align:left}.markdown-body.slides section[data-markdown]:before{content:"";display:block;padding-bottom:56.23%}.markdown-body.slides section[data-markdown]>div:first-child{position:absolute;top:50%;left:1em;right:1em;transform:translateY(-50%);max-height:100%;overflow:hidden}.markdown-body.slides section[data-markdown]>ul{display:inline-block}.markdown-body.slides>section>section+section:after{content:"";position:absolute;top:-1.5em;right:1em;height:1.5em;border:3px solid #777}body{font-smoothing:subpixel-antialiased!important;-webkit-font-smoothing:subpixel-antialiased!important;-moz-osx-font-smoothing:auto!important;text-shadow:0 0 1em transparent,1px 1px 1.2px rgba(0,0,0,.004);-webkit-overflow-scrolling:touch;font-family:Source Sans Pro,Helvetica,Arial,sans-serif;letter-spacing:.025em}.focus,:focus{outline:none!important}::-moz-focus-inner{border:0!important}body.modal-open{overflow-y:auto;padding-right:0!important}
</style>
<!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
<!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
<!--[if lt IE 9]>
<script src="https://cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.min.js" integrity="sha256-3Jy/GbSLrg0o9y5Z5n1uw0qxZECH7C6OQpVBgNFYa0g=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/respond.js/1.4.2/respond.min.js" integrity="sha256-g6iAfvZp+nDQ2TdTR/VVKJf3bGro4ub5fvWSWVRi2NE=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.9/es5-shim.min.js" integrity="sha256-8E4Is26QH0bD52WoQpcB+R/tcWQtpzlCojrybUd7Mxo=" crossorigin="anonymous"></script>
<![endif]-->
</head>
<body>
<div id="doc" class="markdown-body container-fluid" style="position: relative;"><h1 id="logistic-regression"><a class="anchor hidden-xs" href="#logistic-regression" title="logistic-regression"><span class="octicon octicon-link"></span></a>Logistic Regression</h1><h3 id="import-library"><a class="anchor hidden-xs" href="#import-library" title="import-library"><span class="octicon octicon-link"></span></a>import library</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber"><span data-linenumber="1"></span>
<span data-linenumber="2"></span>
<span data-linenumber="3"></span>
<span data-linenumber="4"></span>
<span data-linenumber="5"></span>
<span data-linenumber="6"></span></div><div class="code"><span class="hljs-keyword">import</span> os, sys
<span class="hljs-keyword">import</span> numpy <span class="hljs-keyword">as</span> np
<span class="hljs-keyword">from</span> random <span class="hljs-keyword">import</span> shuffle
<span class="hljs-keyword">import</span> argparse
<span class="hljs-keyword">from</span> math <span class="hljs-keyword">import</span> log, floor
<span class="hljs-keyword">import</span> pandas <span class="hljs-keyword">as</span> pd
</div></div></code></pre><h3 id="io-file"><a class="anchor hidden-xs" href="#io-file" title="io-file"><span class="octicon octicon-link"></span></a>IO File</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="7"></span>
<span data-linenumber="8"></span>
<span data-linenumber="9"></span>
<span data-linenumber="10"></span>
<span data-linenumber="11"></span>
<span data-linenumber="12"></span>
<span data-linenumber="13"></span>
<span data-linenumber="14"></span>
<span data-linenumber="15"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">load_data</span><span class="hljs-params">(train_data_path, train_label_path, test_data_path)</span>:</span>
X_train = pd.read_csv(train_data_path, sep=<span class="hljs-string">','</span>, header=<span class="hljs-number">0</span>)
X_train = np.array(X_train.values)
Y_train = pd.read_csv(train_label_path, sep=<span class="hljs-string">','</span>, header=<span class="hljs-number">0</span>)
Y_train = np.array(Y_train.values)
X_test = pd.read_csv(test_data_path, sep=<span class="hljs-string">','</span>, header=<span class="hljs-number">0</span>)
X_test = np.array(X_test.values)
<span class="hljs-keyword">return</span> (X_train, Y_train, X_test)
</div></div></code></pre><h3 id="define-shuffle"><a class="anchor hidden-xs" href="#define-shuffle" title="define-shuffle"><span class="octicon octicon-link"></span></a>define shuffle</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="16"></span>
<span data-linenumber="17"></span>
<span data-linenumber="18"></span>
<span data-linenumber="19"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">_shuffle</span><span class="hljs-params">(X, Y)</span>:</span>
randomize = np.arange(len(X))
np.random.shuffle(randomize)
<span class="hljs-keyword">return</span> (X[randomize], Y[randomize])
</div></div></code></pre><h3 id="define-normalize"><a class="anchor hidden-xs" href="#define-normalize" title="define-normalize"><span class="octicon octicon-link"></span></a>define normalize</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="20"></span>
<span data-linenumber="21"></span>
<span data-linenumber="22"></span>
<span data-linenumber="23"></span>
<span data-linenumber="24"></span>
<span data-linenumber="25"></span>
<span data-linenumber="26"></span>
<span data-linenumber="27"></span>
<span data-linenumber="28"></span>
<span data-linenumber="29"></span>
<span data-linenumber="30"></span>
<span data-linenumber="31"></span>
<span data-linenumber="32"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">normalize</span><span class="hljs-params">(X_all, X_test)</span>:</span>
<span class="hljs-comment"># Feature normalization with train and test X</span>
X_train_test = np.concatenate((X_all, X_test))
mu = (sum(X_train_test) / X_train_test.shape[<span class="hljs-number">0</span>])
sigma = np.std(X_train_test, axis=<span class="hljs-number">0</span>)
mu = np.tile(mu, (X_train_test.shape[<span class="hljs-number">0</span>], <span class="hljs-number">1</span>))
sigma = np.tile(sigma, (X_train_test.shape[<span class="hljs-number">0</span>], <span class="hljs-number">1</span>))
X_train_test_normed = (X_train_test - mu) / sigma
<span class="hljs-comment"># Split to train, test again</span>
X_all = X_train_test_normed[<span class="hljs-number">0</span>:X_all.shape[<span class="hljs-number">0</span>]]
X_test = X_train_test_normed[X_all.shape[<span class="hljs-number">0</span>]:]
<span class="hljs-keyword">return</span> X_all, X_test
</div></div></code></pre><h3 id="define-split-valid"><a class="anchor hidden-xs" href="#define-split-valid" title="define-split-valid"><span class="octicon octicon-link"></span></a>define split valid</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="33"></span>
<span data-linenumber="34"></span>
<span data-linenumber="35"></span>
<span data-linenumber="36"></span>
<span data-linenumber="37"></span>
<span data-linenumber="38"></span>
<span data-linenumber="39"></span>
<span data-linenumber="40"></span>
<span data-linenumber="41"></span>
<span data-linenumber="42"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">split_valid_set</span><span class="hljs-params">(X_all, Y_all, percentage)</span>:</span>
all_data_size = len(X_all)
valid_data_size = int(floor(all_data_size * percentage))
X_all, Y_all = _shuffle(X_all, Y_all)
X_train, Y_train = X_all[<span class="hljs-number">0</span>:valid_data_size], Y_all[<span class="hljs-number">0</span>:valid_data_size]
X_valid, Y_valid = X_all[valid_data_size:], Y_all[valid_data_size:]
<span class="hljs-keyword">return</span> X_train, Y_train, X_valid, Y_valid
</div></div></code></pre><h3 id="define-sigmoid"><a class="anchor hidden-xs" href="#define-sigmoid" title="define-sigmoid"><span class="octicon octicon-link"></span></a>define sigmoid</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="43"></span>
<span data-linenumber="44"></span>
<span data-linenumber="45"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">sigmoid</span><span class="hljs-params">(z)</span>:</span>
res = <span class="hljs-number">1</span> / (<span class="hljs-number">1.0</span> + np.exp(-z))
<span class="hljs-keyword">return</span> np.clip(res, <span class="hljs-number">1e-8</span>, <span class="hljs-number">1</span>-(<span class="hljs-number">1e-8</span>))
</div></div></code></pre><h3 id="get-valid-score"><a class="anchor hidden-xs" href="#get-valid-score" title="get-valid-score"><span class="octicon octicon-link"></span></a>get valid score</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="46"></span>
<span data-linenumber="47"></span>
<span data-linenumber="48"></span>
<span data-linenumber="49"></span>
<span data-linenumber="50"></span>
<span data-linenumber="51"></span>
<span data-linenumber="52"></span>
<span data-linenumber="53"></span>
<span data-linenumber="54"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">valid</span><span class="hljs-params">(w, b, X_valid, Y_valid)</span>:</span>
valid_data_size = len(X_valid)
z = (np.dot(X_valid, np.transpose(w)) + b)
y = sigmoid(z)
y_ = np.around(y)
result = (np.squeeze(Y_valid) == y_)
print(<span class="hljs-string">'Validation acc = %f'</span> % (float(result.sum()) / valid_data_size))
<span class="hljs-keyword">return</span>
</div></div></code></pre><h3 id="train-model"><a class="anchor hidden-xs" href="#train-model" title="train-model"><span class="octicon octicon-link"></span></a>train model</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="55"></span>
<span data-linenumber="56"></span>
<span data-linenumber="57"></span>
<span data-linenumber="58"></span>
<span data-linenumber="59"></span>
<span data-linenumber="60"></span>
<span data-linenumber="61"></span>
<span data-linenumber="62"></span>
<span data-linenumber="63"></span>
<span data-linenumber="64"></span>
<span data-linenumber="65"></span>
<span data-linenumber="66"></span>
<span data-linenumber="67"></span>
<span data-linenumber="68"></span>
<span data-linenumber="69"></span>
<span data-linenumber="70"></span>
<span data-linenumber="71"></span>
<span data-linenumber="72"></span>
<span data-linenumber="73"></span>
<span data-linenumber="74"></span>
<span data-linenumber="75"></span>
<span data-linenumber="76"></span>
<span data-linenumber="77"></span>
<span data-linenumber="78"></span>
<span data-linenumber="79"></span>
<span data-linenumber="80"></span>
<span data-linenumber="81"></span>
<span data-linenumber="82"></span>
<span data-linenumber="83"></span>
<span data-linenumber="84"></span>
<span data-linenumber="85"></span>
<span data-linenumber="86"></span>
<span data-linenumber="87"></span>
<span data-linenumber="88"></span>
<span data-linenumber="89"></span>
<span data-linenumber="90"></span>
<span data-linenumber="91"></span>
<span data-linenumber="92"></span>
<span data-linenumber="93"></span>
<span data-linenumber="94"></span>
<span data-linenumber="95"></span>
<span data-linenumber="96"></span>
<span data-linenumber="97"></span>
<span data-linenumber="98"></span>
<span data-linenumber="99"></span>
<span data-linenumber="100"></span>
<span data-linenumber="101"></span>
<span data-linenumber="102"></span>
<span data-linenumber="103"></span>
<span data-linenumber="104"></span>
<span data-linenumber="105"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">train</span><span class="hljs-params">(X_all, Y_all, save_dir)</span>:</span>
<span class="hljs-comment"># Split a 10%-validation set from the training set</span>
valid_set_percentage = <span class="hljs-number">0.1</span>
X_train, Y_train, X_valid, Y_valid = split_valid_set(X_all, Y_all, valid_set_percentage)
<span class="hljs-comment"># Initiallize parameter, hyperparameter</span>
w = np.zeros((<span class="hljs-number">106</span>,))
b = np.zeros((<span class="hljs-number">1</span>,))
l_rate = <span class="hljs-number">0.1</span>
batch_size = <span class="hljs-number">32</span>
train_data_size = len(X_train)
step_num = int(floor(train_data_size / batch_size))
epoch_num = <span class="hljs-number">1000</span>
save_param_iter = <span class="hljs-number">50</span>
<span class="hljs-comment"># Start training</span>
total_loss = <span class="hljs-number">0.0</span>
<span class="hljs-keyword">for</span> epoch <span class="hljs-keyword">in</span> range(<span class="hljs-number">1</span>, epoch_num):
<span class="hljs-comment"># Do validation and parameter saving</span>
<span class="hljs-keyword">if</span> (epoch) % save_param_iter == <span class="hljs-number">0</span>:
print(<span class="hljs-string">'=====Saving Param at epoch %d====='</span> % epoch)
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(save_dir):
os.mkdir(save_dir)
np.savetxt(os.path.join(save_dir, <span class="hljs-string">'w'</span>), w)
np.savetxt(os.path.join(save_dir, <span class="hljs-string">'b'</span>), [b,])
print(<span class="hljs-string">'epoch avg loss = %f'</span> % (total_loss / (float(save_param_iter) * train_data_size)))
total_loss = <span class="hljs-number">0.0</span>
valid(w, b, X_valid, Y_valid)
<span class="hljs-comment"># Random shuffle</span>
X_train, Y_train = _shuffle(X_train, Y_train)
<span class="hljs-comment"># Train with batch</span>
<span class="hljs-keyword">for</span> idx <span class="hljs-keyword">in</span> range(step_num):
X = X_train[idx*batch_size:(idx+<span class="hljs-number">1</span>)*batch_size]
Y = Y_train[idx*batch_size:(idx+<span class="hljs-number">1</span>)*batch_size]
z = np.dot(X, np.transpose(w)) + b
y = sigmoid(z)
cross_entropy = <span class="hljs-number">-1</span> * (np.dot(np.squeeze(Y), np.log(y)) + np.dot((<span class="hljs-number">1</span> - np.squeeze(Y)), np.log(<span class="hljs-number">1</span> - y)))
total_loss += cross_entropy
w_grad = np.mean(<span class="hljs-number">-1</span> * X * (np.squeeze(Y) - y).reshape((batch_size,<span class="hljs-number">1</span>)), axis=<span class="hljs-number">0</span>)
b_grad = np.mean(<span class="hljs-number">-1</span> * (np.squeeze(Y) - y))
<span class="hljs-comment"># SGD updating parameters</span>
w = w - l_rate * w_grad
b = b - l_rate * b_grad
<span class="hljs-keyword">return</span>
</div></div></code></pre><h3 id="infer-amp-output-anscsv"><a class="anchor hidden-xs" href="#infer-amp-output-anscsv" title="infer-amp-output-anscsv"><span class="octicon octicon-link"></span></a>infer & output ans.csv</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="106"></span>
<span data-linenumber="107"></span>
<span data-linenumber="108"></span>
<span data-linenumber="109"></span>
<span data-linenumber="110"></span>
<span data-linenumber="111"></span>
<span data-linenumber="112"></span>
<span data-linenumber="113"></span>
<span data-linenumber="114"></span>
<span data-linenumber="115"></span>
<span data-linenumber="116"></span>
<span data-linenumber="117"></span>
<span data-linenumber="118"></span>
<span data-linenumber="119"></span>
<span data-linenumber="120"></span>
<span data-linenumber="121"></span>
<span data-linenumber="122"></span>
<span data-linenumber="123"></span>
<span data-linenumber="124"></span>
<span data-linenumber="125"></span>
<span data-linenumber="126"></span>
<span data-linenumber="127"></span>
<span data-linenumber="128"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">infer</span><span class="hljs-params">(X_test, save_dir, output_dir)</span>:</span>
test_data_size = len(X_test)
<span class="hljs-comment"># Load parameters</span>
print(<span class="hljs-string">'=====Loading Param from %s====='</span> % save_dir)
w = np.loadtxt(os.path.join(save_dir, <span class="hljs-string">'w'</span>))
b = np.loadtxt(os.path.join(save_dir, <span class="hljs-string">'b'</span>))
<span class="hljs-comment"># predict</span>
z = (np.dot(X_test, np.transpose(w)) + b)
y = sigmoid(z)
y_ = np.around(y)
print(<span class="hljs-string">'=====Write output to %s ====='</span> % output_dir)
<span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.exists(output_dir):
os.mkdir(output_dir)
output_path = os.path.join(output_dir, <span class="hljs-string">'log_prediction.csv'</span>)
<span class="hljs-keyword">with</span> open(output_path, <span class="hljs-string">'w'</span>) <span class="hljs-keyword">as</span> f:
f.write(<span class="hljs-string">'id,label\n'</span>)
<span class="hljs-keyword">for</span> i, v <span class="hljs-keyword">in</span> enumerate(y_):
f.write(<span class="hljs-string">'%d,%d\n'</span> %(i+<span class="hljs-number">1</span>, v))
<span class="hljs-keyword">return</span>
</div></div></code></pre><h3 id="main-block"><a class="anchor hidden-xs" href="#main-block" title="main-block"><span class="octicon octicon-link"></span></a>main block</h3><pre><code class="python hljs"><div class="wrapper"><div class="gutter linenumber continue"><span data-linenumber="129"></span>
<span data-linenumber="130"></span>
<span data-linenumber="131"></span>
<span data-linenumber="132"></span>
<span data-linenumber="133"></span>
<span data-linenumber="134"></span>
<span data-linenumber="135"></span>
<span data-linenumber="136"></span>
<span data-linenumber="137"></span>
<span data-linenumber="138"></span>
<span data-linenumber="139"></span>
<span data-linenumber="140"></span>
<span data-linenumber="141"></span>
<span data-linenumber="142"></span>
<span data-linenumber="143"></span>
<span data-linenumber="144"></span>
<span data-linenumber="145"></span>
<span data-linenumber="146"></span>
<span data-linenumber="147"></span>
<span data-linenumber="148"></span>
<span data-linenumber="149"></span>
<span data-linenumber="150"></span>
<span data-linenumber="151"></span>
<span data-linenumber="152"></span>
<span data-linenumber="153"></span>
<span data-linenumber="154"></span>
<span data-linenumber="155"></span>
<span data-linenumber="156"></span>
<span data-linenumber="157"></span>
<span data-linenumber="158"></span>
<span data-linenumber="159"></span>
<span data-linenumber="160"></span>
<span data-linenumber="161"></span>
<span data-linenumber="162"></span>
<span data-linenumber="163"></span>
<span data-linenumber="164"></span>
<span data-linenumber="165"></span>
<span data-linenumber="166"></span>
<span data-linenumber="167"></span></div><div class="code"><span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">main</span><span class="hljs-params">(opts)</span>:</span>
<span class="hljs-comment"># Load feature and label</span>
X_all, Y_all, X_test = load_data(opts.train_data_path, opts.train_label_path, opts.test_data_path)
<span class="hljs-comment"># Normalization</span>
X_all, X_test = normalize(X_all, X_test)
<span class="hljs-comment"># To train or to infer</span>
<span class="hljs-keyword">if</span> opts.train:
train(X_all, Y_all, opts.save_dir)
<span class="hljs-keyword">elif</span> opts.infer:
infer(X_test, opts.save_dir, opts.output_dir)
<span class="hljs-keyword">else</span>:
print(<span class="hljs-string">"Error: Argument --train or --infer not found"</span>)
<span class="hljs-keyword">return</span>
<span class="hljs-keyword">if</span> __name__ == <span class="hljs-string">'__main__'</span>:
parser = argparse.ArgumentParser(description=<span class="hljs-string">'Logistic Regression with Gradient Descent Method'</span>)
group = parser.add_mutually_exclusive_group()
group.add_argument(<span class="hljs-string">'--train'</span>, action=<span class="hljs-string">'store_true'</span>, default=<span class="hljs-keyword">False</span>,
dest=<span class="hljs-string">'train'</span>, help=<span class="hljs-string">'Input --train to Train'</span>)
group.add_argument(<span class="hljs-string">'--infer'</span>, action=<span class="hljs-string">'store_true'</span>,default=<span class="hljs-keyword">False</span>,
dest=<span class="hljs-string">'infer'</span>, help=<span class="hljs-string">'Input --infer to Infer'</span>)
parser.add_argument(<span class="hljs-string">'--train_data_path'</span>, type=str,
default=<span class="hljs-string">'feature/X_train'</span>, dest=<span class="hljs-string">'train_data_path'</span>,
help=<span class="hljs-string">'Path to training data'</span>)
parser.add_argument(<span class="hljs-string">'--train_label_path'</span>, type=str,
default=<span class="hljs-string">'feature/Y_train'</span>, dest=<span class="hljs-string">'train_label_path'</span>,
help=<span class="hljs-string">'Path to training data\'s label'</span>)
parser.add_argument(<span class="hljs-string">'--test_data_path'</span>, type=str,
default=<span class="hljs-string">'feature/X_test'</span>, dest=<span class="hljs-string">'test_data_path'</span>,
help=<span class="hljs-string">'Path to testing data'</span>)
parser.add_argument(<span class="hljs-string">'--save_dir'</span>, type=str,
default=<span class="hljs-string">'logistic_params/'</span>, dest=<span class="hljs-string">'save_dir'</span>,
help=<span class="hljs-string">'Path to save the model parameters'</span>)
parser.add_argument(<span class="hljs-string">'--output_dir'</span>, type=str,
default=<span class="hljs-string">'logistic_output/'</span>, dest=<span class="hljs-string">'output_dir'</span>,
help=<span class="hljs-string">'Path to save the model parameters'</span>)
opts = parser.parse_args()
main(opts)
</div></div></code></pre><div class="resize-sensor" style="position: absolute; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; z-index: -1; visibility: hidden;"><div class="resize-sensor-expand" style="position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: hidden; z-index: -1; visibility: hidden;"><div style="position: absolute; left: 0px; top: 0px; transition: 0s; width: 100000px; height: 100000px;"></div></div><div class="resize-sensor-shrink" style="position: absolute; left: 0; top: 0; right: 0; bottom: 0; overflow: hidden; z-index: -1; visibility: hidden;"><div style="position: absolute; left: 0; top: 0; transition: 0s; width: 200%; height: 200%"></div></div></div></div>
<div class="ui-toc dropup unselectable hidden-print" style="display:none;">
<div class="pull-right dropdown">
<a id="tocLabel" class="ui-toc-label btn btn-default" data-toggle="dropdown" href="#" role="button" aria-haspopup="true" aria-expanded="false" title="Table of content">
<i class="fa fa-bars"></i>
</a>
<ul id="ui-toc" class="ui-toc-dropdown dropdown-menu" aria-labelledby="tocLabel">
<div class="toc"><ul class="nav"><li class=""><a href="#logistic-regression">Logistic Regression</a><ul class="nav"><li><a href="#import-library">import library</a></li><li><a href="#io-file">IO File</a></li><li><a href="#define-shuffle">define shuffle</a></li><li><a href="#define-normalize">define normalize</a></li><li><a href="#define-split-valid">define split valid</a></li><li><a href="#define-sigmoid">define sigmoid</a></li><li><a href="#get-valid-score">get valid score</a></li><li><a href="#train-model">train model</a></li><li><a href="#infer-amp-output-anscsv">infer & output ans.csv</a></li><li><a href="#main-block">main block</a></li></ul></li></ul></div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div>
</ul>
</div>
</div>
<div id="ui-toc-affix" class="ui-affix-toc ui-toc-dropdown unselectable hidden-print" data-spy="affix" style="top:17px;display:none;" >
<div class="toc"><ul class="nav"><li class=""><a href="#logistic-regression">Logistic Regression</a><ul class="nav"><li><a href="#import-library">import library</a></li><li><a href="#io-file">IO File</a></li><li><a href="#define-shuffle">define shuffle</a></li><li><a href="#define-normalize">define normalize</a></li><li><a href="#define-split-valid">define split valid</a></li><li><a href="#define-sigmoid">define sigmoid</a></li><li><a href="#get-valid-score">get valid score</a></li><li><a href="#train-model">train model</a></li><li><a href="#infer-amp-output-anscsv">infer & output ans.csv</a></li><li><a href="#main-block">main block</a></li></ul></li></ul></div><div class="toc-menu"><a class="expand-toggle" href="#">Expand all</a><a class="back-to-top" href="#">Back to top</a><a class="go-to-bottom" href="#">Go to bottom</a></div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js" integrity="sha256-hVVnYaiADRTO2PzUGmuLJr8BLUSjGIZsDYGmIJLv2b8=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha256-U5ZEeKfGNOja007MMD3YBI0A3OSZOQbeG6z2f2Y0hu8=" crossorigin="anonymous" defer></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/gist-embed/2.6.0/gist-embed.min.js" integrity="sha256-KyF2D6xPIJUW5sUDSs93vWyZm+1RzIpKCexxElmxl8g=" crossorigin="anonymous" defer></script>
<script>
var markdown = $(".markdown-body");
//smooth all hash trigger scrolling
function smoothHashScroll() {
var hashElements = $("a[href^='#']").toArray();
for (var i = 0; i < hashElements.length; i++) {
var element = hashElements[i];
var $element = $(element);
var hash = element.hash;
if (hash) {
$element.on('click', function (e) {
// store hash
var hash = this.hash;
if ($(hash).length <= 0) return;
// prevent default anchor click behavior
e.preventDefault();
// animate
$('body, html').stop(true, true).animate({
scrollTop: $(hash).offset().top
}, 100, "linear", function () {
// when done, add hash to url
// (default click behaviour)
window.location.hash = hash;
});
});
}
}
}
smoothHashScroll();
var toc = $('.ui-toc');
var tocAffix = $('.ui-affix-toc');
var tocDropdown = $('.ui-toc-dropdown');
//toc
tocDropdown.click(function (e) {
e.stopPropagation();
});
var enoughForAffixToc = true;
function generateScrollspy() {
$(document.body).scrollspy({
target: ''
});
$(document.body).scrollspy('refresh');
if (enoughForAffixToc) {
toc.hide();
tocAffix.show();
} else {
tocAffix.hide();
toc.show();
}
$(document.body).scroll();
}
function windowResize() {
//toc right
var paddingRight = parseFloat(markdown.css('padding-right'));
var right = ($(window).width() - (markdown.offset().left + markdown.outerWidth() - paddingRight));
toc.css('right', right + 'px');
//affix toc left
var newbool;
var rightMargin = (markdown.parent().outerWidth() - markdown.outerWidth()) / 2;
//for ipad or wider device
if (rightMargin >= 133) {
newbool = true;
var affixLeftMargin = (tocAffix.outerWidth() - tocAffix.width()) / 2;
var left = markdown.offset().left + markdown.outerWidth() - affixLeftMargin;
tocAffix.css('left', left + 'px');
} else {
newbool = false;
}
if (newbool != enoughForAffixToc) {
enoughForAffixToc = newbool;
generateScrollspy();
}
}
$(window).resize(function () {
windowResize();
});
$(document).ready(function () {
windowResize();
generateScrollspy();
});
//remove hash
function removeHash() {
window.location.hash = '';
}
var backtotop = $('.back-to-top');
var gotobottom = $('.go-to-bottom');
backtotop.click(function (e) {
e.preventDefault();
e.stopPropagation();
if (scrollToTop)
scrollToTop();
removeHash();
});
gotobottom.click(function (e) {
e.preventDefault();
e.stopPropagation();
if (scrollToBottom)
scrollToBottom();
removeHash();
});
var toggle = $('.expand-toggle');
var tocExpand = false;
checkExpandToggle();
toggle.click(function (e) {
e.preventDefault();
e.stopPropagation();
tocExpand = !tocExpand;
checkExpandToggle();
})
function checkExpandToggle () {
var toc = $('.ui-toc-dropdown .toc');
var toggle = $('.expand-toggle');
if (!tocExpand) {
toc.removeClass('expand');
toggle.text('Expand all');
} else {
toc.addClass('expand');
toggle.text('Collapse all');
}
}
function scrollToTop() {
$('body, html').stop(true, true).animate({
scrollTop: 0
}, 100, "linear");
}
function scrollToBottom() {
$('body, html').stop(true, true).animate({
scrollTop: $(document.body)[0].scrollHeight
}, 100, "linear");
}
</script>
</body>
</html>