-
Notifications
You must be signed in to change notification settings - Fork 7
/
2020-ml-intro-ssh.html
1213 lines (937 loc) · 33.9 KB
/
2020-ml-intro-ssh.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
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>ML Supervised Intro</title>
<meta name="description" content="ML Supervised Intro">
<meta name="author" content="Oliver Zeigermann">
<meta name="apple-mobile-web-app-capable" content="yes"/>
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent"/>
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, minimal-ui">
<link rel="stylesheet" href="reveal.js/css/reveal.css">
<!--<link rel="stylesheet" href="reveal.js/css/theme/white.css" id="theme">-->
<!--<link rel="stylesheet" href="reveal.js/css/theme/black.css" id="theme">-->
<!--<link rel="stylesheet" href="reveal.js/css/theme/night.css" id="theme">-->
<!--<link rel="stylesheet" href="reveal.js/css/theme/simple.css" id="theme">-->
<link rel="stylesheet" href="reveal.js/css/theme/solarized.css" id="theme">
<!-- Code syntax highlighting -->
<link rel="stylesheet" href="reveal.js/lib/css/zenburn.css">
<style>
/*pre code {*/
/*display: block;*/
/*padding: 0.5em;*/
/*background: #FFFFFF !important;*/
/*color: #000000 !important;*/
/*}*/
.right-img {
margin-left: 10px !important;
float: right;
height: 500px;
}
.todo:before {
content: 'TODO: ';
}
.todo {
color: red !important;
}
code span.line-number {
color: lightcoral;
}
.reveal pre code {
max-height: 1000px !important;
}
img {
border: 0 !important;
box-shadow:0 0 0 0 !important;
}
.reveal {
-ms-touch-action: auto !important;
touch-action: auto !important;
}
.reveal h2,
.reveal h3,
.reveal h4 {
letter-spacing: 2px;
font-family: 'Calibri', sans-serif;
/* font-family: 'Times New Roman', Times, serif; */
font-weight: bold;
color: black;
font-style: italic;
letter-spacing: -2px;
text-transform: none !important;
}
.reveal em {
font-weight: bold;
}
.reveal .step-subtitle h1 {
letter-spacing: 1px;
}
.reveal .step-subtitle h2,
.reveal .step-subtitle h3 {
text-transform: none;
font-style: italic;
font-weight: normal;
/* font-weight: 400; */
/* font-family: 'Amiri', serif; */
font-family: 'Lobster', serif;
letter-spacing: 1px;
color: #2aa198;
text-decoration: underline;
}
.reveal .front-page h1,
.reveal .front-page h2 {
font-family: "League Gothic";
font-style: normal;
text-transform: uppercase !important;
letter-spacing: 1px;
}
.reveal .front-page h1 {
font-size: 2.5em !important;
}
.reveal .highlight {
background-color: #D3337B;
color: white;
}
.reveal section img {
background: none;
}
.reveal img.with-border {
border: 1px solid #586e75 !important;
box-shadow: 3px 3px 1px rgba(0, 0, 0, 0.15) !important;
}
.reveal li {
margin-bottom: 8px;
}
/* For li's that use FontAwesome icons as bullet-point */
.reveal ul.fa-ul li {
list-style-type: none;
}
.reveal {
color: black !important;
}
</style>
<!-- Printing and PDF exports -->
<script>
var link = document.createElement('link');
link.rel = 'stylesheet';
link.type = 'text/css';
var printMode = window.location.search.match(/print-pdf/gi);
link.href = printMode ? 'reveal.js/css/print/pdf.css' : 'reveal.js/css/print/paper.css';
document.getElementsByTagName('head')[0].appendChild(link);
</script>
<!--[if lt IE 9]>
<script src="reveal.js/lib/js/html5shiv.js"></script>
<![endif]-->
</head>
<body style="background-color: whitesmoke;">
<div class="reveal">
<div class="slides">
<!-- <section data-markdown class="todo">
<textarea data-template>
</textarea>
</section> -->
<!-- <section data-markdown class="todo">
<textarea data-template>
### Abschluss-Übung
- Male deinen eigenen Datensatz und versuche ihn zu fitten
- Entweder Line Chart für 01 oder Scatter Plot für 02
- Generalisierung sicher stellen (wie in 03 gelernt)
- Code vorgeben, der das Laden kann
https://drawdata.xyz/
</textarea>
</section> -->
<section>
<h2>ML Supervised Intro</h2>
<h4><a href="http://zeigermann.eu">Oliver Zeigermann</a> /
<a href="http://twitter.com/djcordhose">@DJCordhose</a>
</h4>
</section>
<section data-markdown>
<textarea data-template>
### Our Scenario for today: Predicting Risk
* We are CTO of a highly innovative Car Insurance Company
* Different from other insurance companies we determine the rate by the actual number of accidents per customer
* _Objective: how many accidents will prospective customers have?_
<img src='img/pixabay/accident-151668_1280.png' height="300px">
</textarea>
</section>
<section>
<h3>Classification based on known data</h3>
<img src="img/applications/all.png" height="500px" class="fragment">
</section>
<section data-markdown>
<textarea data-template>
### Exercise : Manually separate areas of different customer types
_team up and discuss with your team_
<div style="font-size: large;">
* <a data-ex='ex1-gr1'>Team 1</a>: <span data-ex='ex1-gr1'>broken</span>
* <a data-ex='ex1-gr2'>Team 2</a>: <span data-ex='ex1-gr2'>broken</span>
* <a data-ex='ex1-gr3'>Team 3</a>: <span data-ex='ex1-gr3'>broken</span>
* <a data-ex='ex1-gr4'>Team 4</a>: <span data-ex='ex1-gr4'>broken</span>
</div>
_Exercise in Mural App_
</textarea>
</section>
<!-- <section data-markdown>
<textarea data-template>
### Exercise I Understanding the Supervised Learning Approach
_bear in mind, you want to use this for prediction_
<a href='exercise/2020-applications.pdf'>Exercise as PDF</a>
</textarea>
</section> -->
<section data-markdown >
<textarea data-template>
### Two Sample Solutions
<img src='img/decision-boundaries/decision-boundaries-train.jpg'>
<small>
Are they the same? What is the key difference?
</small>
</textarea>
</section>
<!-- <section data-markdown id='supervised-2'>
<textarea data-template>
## Core Question
### Can we automate this process of drawing Decision Boundaries?
</textarea>
</section>
-->
<section data-markdown>
<textarea data-template>
## How to solve this programmatically?
</textarea>
</section>
<!-- <section data-markdown id='supervised-2'>
<textarea data-template>
<img src='img/classic-development.jpg'>
</textarea>
</section> -->
<section style="font-size: larger;">
<h3>Programmer's approach: Code Rules by Hand</h3>
<div class="fragment">
<pre><code contenteditable data-trim class="line-numbers python">
def calculate_risk(age, speed):
if age < 25:
if speed > 110:
return high # young people, fast cars
else:
return medium # young people
</code></pre>
</div>
<div class="fragment">
<pre><code contenteditable class="line-numbers python"> if age > 70:
return high # seniors</code></pre>
</div>
<div class="fragment">
<pre><code contenteditable class="line-numbers python"> if speed > 145:
return high # fast cars in general</code></pre>
</div>
<div class="fragment">
<pre><code contenteditable class="line-numbers python"> # this default vastly simplifies rule set
return low # otherwise</code></pre>
</div>
</section>
<section data-markdown>
<textarea data-template>
### How good is this?
* Is it better than guessing?
* Are all the rules correct?
* Are some missing?
* How would we even know?
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### How good is our Rule based approach?
Plotting the predictions as a background
<img src='img/applications/rules.png' class="fragment" height="450px">
<br>
<small class="fragment">approx. 57% predictions correct</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Baseline to understand if our score is good
<img src="img/applications/random.png" height="450px" class="fragment">
<small class="fragment">only gets 33% right</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Do we really have to write those rules by hand?
</textarea>
</section>
<section data-markdown>
<textarea data-template>
<img src='img/supervised-ml.jpg' height="650px">
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Step I
## Data Preparation
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Data is King
_collecting data might be the hardest part of the job_
* but also the most important
* no data, not good quality or quantity => no supervised machine learning
* if we have a simulator, reinforcement learning might be an option
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Data and Process are king
<img src='img/googleml/model-architecture-not-important.jpg'>
<small>
https://developers.google.com/machine-learning/guides/rules-of-ml/
</small>
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Shared Exercise: Clean Data and Select Features
<img src='img/insurance/data.png' height="500">
</textarea>
</section>
<section data-markdown style="font-size: xx-large;">
<textarea data-template>
### Questions
_Data Cleaning_
* What errors do you find in the data? Mark on paper and describe
* How to deal with those errors?
_Feature Selection_
* Which column would you predict? Do you like its encoding?
* Which columns would you use as input for training?
* Would you use all columns? If not, why?
* Which columns have the most predictive power?
<!--
- Datendopplung Zeile 4/5 => eine löschen
- Fehlender Wert Zeile 16 => Zeile löschen oder Durchschnitt
- Spalte 'state' mit mehr als 50% fehlenden Werten
- Zeile 23 Ausreißer: Zeile löschen oder auf plausiblen Wert korrigieren
- Zeile 24: Califorina
-->
</textarea>
</section>
<!-- <section data-markdown>
<textarea data-template>
### Exercise - Data Cleaning and Feature Selection
_team up and discuss with your team_
* <a id='ex2-gr1'>Team 1</a>
* <a id='ex2-gr2'>Team 2</a>
* <a id='ex2-gr3'>Team 3</a>
* <a id='ex2-gr4'>Team 4</a>
_Exercise in Mural App_
</textarea>
</section>
-->
<section data-markdown style="font-size: xx-large" >
<textarea data-template>
### Results: Data Cleaning und Feature Selection
_Data Cleaning_
* Typos: Califorina
* Outliers: Delete line or replace with decent value
* Doubles: Delete
* Missing Value: Delete line or replace with imputed value
_Feature Selection_
* Make sure which value to predict
* Row missing more than 50% of values: do not use
* Explore dependencies to decide what to use for training input
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Step II
## Exploratory Data Analysis and Checking
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Pairplot
<img src='img/applications/scatter.png' height="550px">
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Basic Statistical Metrics
<img src='img/insurance/df_describe.png' height="500">
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Linear correlations
<img src='img/insurance/cm.png' height="550px">
</textarea>
</section>
<!-- <section data-markdown>
<textarea data-template>
### Working with Colab Notebooks
https://colab.research.google.com
</textarea>
</section> -->
<section data-markdown>
<textarea data-template>
### Literate Statistical Programming
* Intent
* Code
* Data
* Results
* (Interpretation)
_Idee implemented in so called "notebooks"_
<small>https://en.wikipedia.org/wiki/Literate_programming</small>
<small>https://education.arcus.chop.edu/literate-statistical-programming/</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Exercise: Run your first Colab Notebook
* In a first pass we will go through the notebook together
* Open the notebook and sign into your Google account or register a new one
* Execute the analysis above in the notebook until it tells you to stop
* Try to answer the questions on the next slide
* Save your notebook in your Google Drive (or on Github if you want to)
<small>Notebook: https://colab.research.google.com/github/djcordhose/ml-workshop/blob/master/notebooks/intro/supervised.ipynb</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Discussion
1. which feature has the most predictive power and
1. which has the lowest?
1. which features shall we use for training?
_Is there anything else you find interesting or surprising?_
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Step III
## Training from Data
</textarea>
</section>
<section data-markdown >
<textarea data-template>
#### Training from Data, but how?
<img src='img/abstractness.png'>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Use ready made model over API
<img src='img/google-nlp-api.png' height="500">
<small>https://cloud.google.com/natural-language</small>
</textarea>
</section>
<section>
<h4>Use Off-the shelf Neuronal Network (fully trained)</h4>
<img src='img/cat-bonkers.png' height="300">
<pre style="font-size: xx-large;"><code contenteditable data-trim class="python">
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2
model = MobileNetV2(weights='imagenet', input_shape=(224, 224, 3))
prediction = model.predict(img)
> ('n02124075', 'Egyptian_cat', 0.43944412)
</code></pre>
<small>MobileNet on Imagenet data with Keras</small>
</section>
<section>
<h3>Train Off-the shelf Neuronal Network (structure only)</h3>
<p>Training</p>
<pre style="font-size: xx-large;"><code contenteditable data-trim class="python">
from tensorflow.keras.applications.mobilenet_v2 import MobileNetV2
model = MobileNetV2(classes=num_classes, weights=None,
input_shape=(1920, 1080, 3))
model.compile(loss='sparse_categorical_crossentropy',
optimizer='adam')
model.fit(X, y)
</code></pre>
<p>Prediction</p>
<pre style="font-size: xx-large;"><code contenteditable data-trim class="line-numbers python">
prediction = model.predict(img)
> ('n02124075', 'Egyptian_cat', 0.43944412)
</code></pre>
<small>untrained MobileNet with Keras</small>
</section>
<section>
<h3>Train traditionell ML Algorithm</h3>
<p>Training</p>
<pre style="font-size: xx-large;"><code contenteditable data-trim class="line-numbers python">
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X, y)
</code></pre>
<p>Prediction</p>
<pre style="font-size: xx-large;"><code contenteditable data-trim class="line-numbers python">
y_pred = clf.predict(input)
</code></pre>
<small>Decision Tree mit Sklearn</small>
</section>
<section>
<h4>Create and Train custom Neuronal Network (standard Architecture)</h4>
<pre style="font-size: xx-large;"><code contenteditable data-trim class="line-numbers python">
model = tf.keras.Sequential()
model.add(Conv2D(filters=32, activation='relu')
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(dropout))
model.add(Conv2D(filters=64, activation='relu'))
model.add(BatchNormalization())
model.add(MaxPooling2D(pool_size=2))
model.add(Dropout(dropout))
model.add(Flatten())
model.add(Dense(256, activation='relu'))
model.add(Dropout(dropout))
model.add(Dense(num_classes, activation='softmax'))
</code></pre>
<small>VGG in TensorFlow</small>
</section>
<section>
<h3>Do whatever on tensor level</h3>
<pre style="font-size: xx-large;"><code contenteditable data-trim class="line-numbers python">
init W, U, V
for i in range(0, len(X)):
x = X[i]
h = torch.zeros(nhidden, 1)
for t in range(len(x)):
h = W@h + U@onehot(x[t])
h = torch.relu(h)
o = V@h
o = softmax(o)
loss = cross_entropy(o, y[i])
update W,U,V towards lower loss
</code></pre>
<small>BOW in Pytorch <br><a href='https://explained.ai/rnn/implementation.html#sec:1.5'>https://explained.ai/rnn/implementation.html#sec:1.5</a></small>
</section>
<section data-markdown >
<textarea data-template>
#### Choosing the middle - Decision Tree (Traditional ML)
<img src='img/abstractness.png' height="500px">
<small>There is no standard NN architecture and custom NNs might be overkill</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Decision Trees can learn such rules (simplified)
<img src="img/applications/tree_interp.png">
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Decision Boundaries for our Decision Tree
Plotting the predictions as a background
<img src="img/applications/dt-test.png" height="450px">
<br>
<small>Up to 70% accuracy on unknown data</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Comparing to our Rule based approach
<img src='img/applications/rules.png' height="450px">
<br>
<small>approx. 56% predictions correct</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Complete tree for plot on previous slide
<img src="img/applications/tree_shallow.png">
</textarea>
</section>
<section style="font-size: larger;">
<h3>Code in Scikit-learn</h3>
<p>Training</p>
<pre><code contenteditable data-trim class="fragment line-numbers python">
from sklearn.tree import DecisionTreeClassifier
clf = DecisionTreeClassifier()
clf.fit(X, y)
</code></pre>
<p>Prediction</p>
<pre><code contenteditable data-trim class="fragment line-numbers python">
y_pred = clf.predict(input)
</code></pre>
<small>
<a href='https://scikit-learn.org/stable/modules/classes.html'>https://scikit-learn.org/stable/modules/classes.html</a>
<br>
<br>
<a href='https://colab.research.google.com/github/djcordhose/ml-workshop/blob/master/notebooks/intro/supervised.ipynb'>
https://colab.research.google.com/github/djcordhose/ml-workshop/blob/master/notebooks/intro/supervised.ipynb</a>
</small>
</section>
<!-- <section data-markdown>
<textarea data-template>
### How is the Decision Tree being Constructed?
We are using the CART algorithm:
* top-down split the set of examples into two new sets
* choose a variable and a value at each step that best splits our customer example
* terminal node when no further gain possible or regularization kicks in
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### What is the best split?
* choose a feature to split on (either random or best)
* assign a category to each node containing a certain set of samples
* use a metric (Gini or Entropy) to decide how good a node would be based on that category
* sum up weighted metric for both child nodes
* optimize the split for that summed metric
<small>
https://machinelearningmastery.com/classification-and-regression-trees-for-machine-learning/
</small>
</textarea>
</section> -->
<section data-markdown>
<textarea data-template>
### How is the Decision Tree being Constructed?
<img src="img/cart.png" height=500>
<small>
http://scikit-learn.org/stable/modules/tree.html#tree-algorithms-id3-c4-5-c5-0-and-cart
</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### What is the best split?
* assign a category to each node containing a certain set of samples
* use a metric (Gini or Entropy) to decide how good a node would be based on that category
* sum up weighted metric for both child nodes
* optimize the split for that summed metric
<small>https://machinelearningmastery.com/classification-and-regression-trees-for-machine-learning/</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Exercise: Train a Decision Tree
* Stay in the same notebook as before
* Execute more cells until the notebook tells you to stop
* Train the model and see how it would classify yourself
* Save your notebook in your Google Drive (or on Github if you want to)
<small>Notebook: https://colab.research.google.com/github/djcordhose/ml-workshop/blob/master/notebooks/intro/supervised.ipynb</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## coup de theatre
### sudden sensational turn in a play
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Step IV
## Evaluation
</textarea>
</section>
<section data-markdown>
<textarea data-template>
## Machine Learning is all about Generalization
1. Learn from known data
1. _Make predictions on unknown data_
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### So Supervised Machine Learning is all about the data you have not seen, yet
## How to make sure your classification works well on unseen data?
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### The trick: Split known data
<img class='fragment' src='img/generalization.jpg' height="550px">
</textarea>
</section>
<!--
- Unlock all
For each group
- Ungroup
- Delect, Select first
- Delete
-->
<section data-markdown>
<textarea data-template>
### Exercise (shared): How well did you generalize?
<div style="font-size: large;">
* <a data-ex='ex1-gr1'>Team 1</a>: <span data-ex='ex1-gr1'>broken</span>
* <a data-ex='ex1-gr2'>Team 2</a>: <span data-ex='ex1-gr2'>broken</span>
* <a data-ex='ex1-gr3'>Team 3</a>: <span data-ex='ex1-gr3'>broken</span>
* <a data-ex='ex1-gr4'>Team 4</a>: <span data-ex='ex1-gr4'>broken</span>
</div>
_What would you have done differently if you had known this is all about generalization?_
<small>
Olli muss folgendes für jede Gruppe tun: unlock, ungroup, deselect, select first, delete
</small>
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Remember the two sample solutions?
<img src='img/decision-boundaries/decision-boundaries-train.jpg'>
<small>
Are they the same? What is the key difference?
</small>
</textarea>
</section>
<section data-markdown >
<textarea data-template>
### Now on test data
<img src='img/decision-boundaries/decision-boundaries-test.jpg'>
<small>
Which one is better? Why?
</small>
</textarea>
</section>
<section id='overfitting'>
<h3>The Issue: Overfitting</h2>
<div>
<div style="float: left">
<img src="img/elements/80_percent.jpg" height="200" class="fragment" data-fragment-index='1'>
<p>
<small><em>Training Score</em></small>
</p>
</div>
<div style="float: left" class="fragment" data-fragment-index='5'>
<img src="img/elements/down.jpg" height="200">
</div>
<div style="float: left" class="fragment" data-fragment-index='4'>
<img src="img/elements/up.jpg" height="200">
</div>
<div style="float: left">
<img src="img/elements/70_percent.jpg" height="225" class="fragment" data-fragment-index='2'>
<p>
<small><em>Test Score</em></small>
</p>
</div>
</div>
<p style="clear: both" class="fragment" data-fragment-index='3'><em>Training and test scores clearly divert</em></p>
</section>
<section>
<h3>A different setting: this generalizes well, but has another issue</h3>
<div style="max-width: 50%; float: left;">
<img src='img/decision-boundaries/underfit-train.jpg' height="300">
<small>Training Data</small>
</div>
<div style="max-width: 50%; float: right;">
<img src='img/decision-boundaries/underfit-test.jpg' height="300">
<small>Test Data</small>
</div>
<p style="clear: both;" class="fragment">
<em>
If both test and training are pretty bad, this is called <em>underfitting</em>
</em>
</p>
</section>
<section data-markdown>
<textarea data-template>
### Regularization
_Process to counter overfitting_
Each ML strategy has its own means of Regularization, e.g.
* KNN: more neighbors
* Decision Trees: reduce depth, use ensembles
* NN: Dropout, Batch Normalization, Reduced Capacity, Reduced Training Time
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Example: Regularization on complex decision tree
<img src="img/applications/tree_deep.png">
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Reduced depth
<img src="img/applications/tree_shallow.png">
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Exercise: Regularize your Decision tree
* Continue with your notebook from where you stopped
* Execute the rest of the notebook
* Change the maximum depth, maximum number of leaves, and minimum samples per leaf of the decision tree to fight overfitting
* What is your best depth?
* How do the decision boundaries change?
* What are your best scores?
* Save your notebook in your Google Drive (or on Github if you want to)
<small>Notebook: https://colab.research.google.com/github/djcordhose/ml-workshop/blob/master/notebooks/intro/supervised.ipynb</small>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Overview: Supervised Learning Process Flow
<img src='img/flow-train.jpg'>
</textarea>
</section>
<section data-markdown>
<textarea data-template>
### Be Careful: Good Test Score is no Guarantee
<img src='img/data-and-the-world.jpg' height="550px">
</textarea>
</section>