Experimental Design + k-Nearest Neighbors KNN Readings: Prob. - - PowerPoint PPT Presentation

experimental design k nearest neighbors
SMART_READER_LITE
LIVE PREVIEW

Experimental Design + k-Nearest Neighbors KNN Readings: Prob. - - PowerPoint PPT Presentation

10-601 Introduction to Machine Learning Machine Learning Department School of Computer Science Carnegie Mellon University Experimental Design + k-Nearest Neighbors KNN Readings: Prob. Readings: (next


slide-1
SLIDE 1

Experimental ¡Design + k-­‑Nearest ¡Neighbors

1

KNN ¡Readings: Mitchell ¡8.2 HTF ¡13.3 Murphy ¡-­‑-­‑-­‑ Bishop ¡2.5.2

  • Prob. ¡Readings: ¡(next ¡lecture)

Lecture ¡notes ¡from ¡10-­‑600 ¡ (See ¡Piazza ¡post ¡for ¡the ¡pointers) Murphy ¡2 Bishop ¡2 HTF ¡-­‑-­‑ Mitchell ¡-­‑-­‑

10-­‑601 ¡Introduction ¡to ¡Machine ¡Learning

Matt ¡Gormley Lecture ¡3 January ¡25, ¡2016

Machine ¡Learning ¡Department School ¡of ¡Computer ¡Science Carnegie ¡Mellon ¡University

slide-2
SLIDE 2

Reminders

  • Background Exercises (Homework 1)

– Released: ¡Wed, ¡Jan. ¡25 – Due: ¡Mon, ¡Jan. ¡30 ¡at ¡5:30pm

  • Website updates

– Office ¡hours Google ¡calendar ¡on “People” – Readings on “Schedule”

  • Meet AIs: ¡Sarah, ¡Daniel, ¡Brynn

2

slide-3
SLIDE 3

Outline

  • k-­‑Nearest ¡Neighbors ¡(KNN)

– Special ¡cases – Choosing ¡k – Case ¡Study: ¡KNN ¡on ¡Fisher ¡Iris ¡Data – Case ¡Study: ¡KNN ¡on ¡2D ¡Gaussian ¡Data

  • Experimental ¡Design

– Train ¡error ¡vs. ¡test ¡error – Train ¡/ ¡validation ¡/ ¡test ¡splits – Cross-­‑validation

  • Function ¡Approximation ¡View ¡of ¡ML

3

slide-4
SLIDE 4

K-­‑NEAREST ¡NEIGHBORS

4

slide-5
SLIDE 5

k-­‑Nearest ¡Neighbors

Whiteboard:

– Special ¡cases – Choosing ¡k

5

slide-6
SLIDE 6

KNN ¡ON ¡FISHER ¡IRIS ¡DATA

6

slide-7
SLIDE 7

Fisher ¡Iris ¡Dataset

Fisher ¡(1936) ¡used ¡150 ¡measurements ¡of ¡flowers ¡ from ¡3 ¡different ¡species: ¡Iris ¡setosa (0), ¡Iris ¡ virginica (1), ¡Iris ¡versicolor (2) ¡collected ¡by ¡ Anderson ¡(1936)

7

Full ¡dataset: ¡https://en.wikipedia.org/wiki/Iris_flower_data_set Species Sepal ¡ Length Sepal ¡ Width Petal ¡ Length Petal ¡ Width 4.3 3.0 1.1 0.1 4.9 3.6 1.4 0.1 5.3 3.7 1.5 0.2 1 4.9 2.4 3.3 1.0 1 5.7 2.8 4.1 1.3 1 6.3 3.3 4.7 1.6 1 6.7 3.0 5.0 1.7

slide-8
SLIDE 8

KNN ¡on ¡Fisher ¡Iris ¡Data

8

slide-9
SLIDE 9

KNN ¡on ¡Fisher ¡Iris ¡Data

9

Special ¡Case: ¡Nearest ¡Neighbor

slide-10
SLIDE 10

KNN ¡on ¡Fisher ¡Iris ¡Data

10

Special ¡Case: ¡Majority ¡Vote

slide-11
SLIDE 11

KNN ¡on ¡Fisher ¡Iris ¡Data

11

slide-12
SLIDE 12

KNN ¡on ¡Fisher ¡Iris ¡Data

12

Special ¡Case: ¡Nearest ¡Neighbor

slide-13
SLIDE 13

KNN ¡on ¡Fisher ¡Iris ¡Data

13

slide-14
SLIDE 14

KNN ¡on ¡Fisher ¡Iris ¡Data

14

slide-15
SLIDE 15

KNN ¡on ¡Fisher ¡Iris ¡Data

15

slide-16
SLIDE 16

KNN ¡on ¡Fisher ¡Iris ¡Data

16

slide-17
SLIDE 17

KNN ¡on ¡Fisher ¡Iris ¡Data

17

slide-18
SLIDE 18

KNN ¡on ¡Fisher ¡Iris ¡Data

18

slide-19
SLIDE 19

KNN ¡on ¡Fisher ¡Iris ¡Data

19

slide-20
SLIDE 20

KNN ¡on ¡Fisher ¡Iris ¡Data

20

slide-21
SLIDE 21

KNN ¡on ¡Fisher ¡Iris ¡Data

21

slide-22
SLIDE 22

KNN ¡on ¡Fisher ¡Iris ¡Data

22

slide-23
SLIDE 23

KNN ¡on ¡Fisher ¡Iris ¡Data

23

slide-24
SLIDE 24

KNN ¡on ¡Fisher ¡Iris ¡Data

24

slide-25
SLIDE 25

KNN ¡on ¡Fisher ¡Iris ¡Data

25

slide-26
SLIDE 26

KNN ¡on ¡Fisher ¡Iris ¡Data

26

slide-27
SLIDE 27

KNN ¡on ¡Fisher ¡Iris ¡Data

27

slide-28
SLIDE 28

KNN ¡on ¡Fisher ¡Iris ¡Data

28

slide-29
SLIDE 29

KNN ¡on ¡Fisher ¡Iris ¡Data

29

slide-30
SLIDE 30

KNN ¡on ¡Fisher ¡Iris ¡Data

30

slide-31
SLIDE 31

KNN ¡on ¡Fisher ¡Iris ¡Data

31

slide-32
SLIDE 32

KNN ¡on ¡Fisher ¡Iris ¡Data

32

Special ¡Case: ¡Majority ¡Vote

slide-33
SLIDE 33

KNN ¡ON ¡GAUSSIAN ¡DATA

33

slide-34
SLIDE 34

KNN ¡on ¡Gaussian ¡Data

34

slide-35
SLIDE 35

KNN ¡on ¡Gaussian ¡Data

35

slide-36
SLIDE 36

KNN ¡on ¡Gaussian ¡Data

36

slide-37
SLIDE 37

KNN ¡on ¡Gaussian ¡Data

37

slide-38
SLIDE 38

KNN ¡on ¡Gaussian ¡Data

38

slide-39
SLIDE 39

KNN ¡on ¡Gaussian ¡Data

39

slide-40
SLIDE 40

KNN ¡on ¡Gaussian ¡Data

40

slide-41
SLIDE 41

KNN ¡on ¡Gaussian ¡Data

41

slide-42
SLIDE 42

KNN ¡on ¡Gaussian ¡Data

42

slide-43
SLIDE 43

KNN ¡on ¡Gaussian ¡Data

43

slide-44
SLIDE 44

KNN ¡on ¡Gaussian ¡Data

44

slide-45
SLIDE 45

KNN ¡on ¡Gaussian ¡Data

45

slide-46
SLIDE 46

KNN ¡on ¡Gaussian ¡Data

46

slide-47
SLIDE 47

KNN ¡on ¡Gaussian ¡Data

47

slide-48
SLIDE 48

KNN ¡on ¡Gaussian ¡Data

48

slide-49
SLIDE 49

KNN ¡on ¡Gaussian ¡Data

49

slide-50
SLIDE 50

KNN ¡on ¡Gaussian ¡Data

50

slide-51
SLIDE 51

KNN ¡on ¡Gaussian ¡Data

51

slide-52
SLIDE 52

KNN ¡on ¡Gaussian ¡Data

52

slide-53
SLIDE 53

KNN ¡on ¡Gaussian ¡Data

53

slide-54
SLIDE 54

KNN ¡on ¡Gaussian ¡Data

54

slide-55
SLIDE 55

KNN ¡on ¡Gaussian ¡Data

55

slide-56
SLIDE 56

KNN ¡on ¡Gaussian ¡Data

56

slide-57
SLIDE 57

KNN ¡on ¡Gaussian ¡Data

57

slide-58
SLIDE 58

KNN ¡on ¡Gaussian ¡Data

58

slide-59
SLIDE 59

CHOOSING ¡THE ¡NUMBER ¡OF ¡ NEIGHBORS

59

slide-60
SLIDE 60

F-­‑Fold ¡Cross-­‑Validation

Key ¡idea: ¡rather ¡than ¡just ¡a ¡single ¡“validation” ¡set, ¡use ¡ many! ¡(Error ¡is ¡more ¡stable. ¡Slower ¡computation.)

60

(Name ¡changed ¡from ¡K-­‑Fold ¡Cross-­‑Validation ¡to ¡avoid ¡confusion ¡with ¡KNN)

D = y(1)

y(2) y(N) x(1) x(2) x(N)

Fold ¡1 Fold ¡2 Fold ¡3 Fold ¡4

Divide ¡data ¡into ¡folds ¡(e.g. ¡4) 1. Train ¡on ¡folds ¡{1,2,3} ¡and ¡ predict ¡on ¡{4} 2. Train ¡on ¡folds ¡{1,2,4} ¡and ¡ predict ¡on ¡{3} 3. Train ¡on ¡folds ¡{1,3,4} ¡and ¡ predict ¡on ¡{2} 4. Train ¡on ¡folds ¡{2,3,4} ¡and ¡ predict ¡on ¡{1} Concatenate ¡all ¡the ¡ predictions ¡and ¡evaluate ¡ error

slide-61
SLIDE 61

Math ¡as ¡Code

It ¡depends ¡on ¡how ¡large ¡the ¡set ¡Y ¡is! If ¡it’s ¡a ¡small ¡enumerable ¡set ¡Y ¡= ¡{1,2,…,77}, ¡ then:

61

ymax = ¡argmax f(y)

y ¡∈ Y ¡

How ¡to ¡implement?

ymax = -inf for for y in in {1,2,…77}: if if f(y) > ymax: ymax = y return eturn ymax

slide-62
SLIDE 62

Math ¡as ¡Code

It ¡depends ¡on ¡how ¡large ¡the ¡set ¡Y ¡is! If ¡it’s ¡a ¡small ¡enumerable ¡set ¡Y ¡= ¡{1,2,…,77}, ¡ then:

62

vmax = ¡max f(y)

y ¡∈ Y ¡

How ¡to ¡implement?

vmax = -inf for for y in in {1,2,…77}: if if f(y) > vmax: vmax = f(y) return eturn vmax

slide-63
SLIDE 63

Function ¡Approximation ¡View ¡of ¡ML

Whiteboard

63

slide-64
SLIDE 64

Beyond ¡the ¡Scope ¡of ¡This ¡Lecture

  • k-­‑Nearest ¡Neighbors ¡(KNN) ¡for ¡Regression
  • Distance-­‑weighted KNN
  • Cover ¡& ¡Hart ¡(1967) ¡Bayes ¡error ¡rate ¡bound
  • KNN ¡for ¡Facial ¡Recognition ¡(see ¡Eigenfaces

in ¡PCA ¡lecture)

64

slide-65
SLIDE 65

Takeaways

  • k-­‑Nearest ¡Neighbors

– Requires ¡careful ¡choice ¡of ¡k ¡(# ¡of ¡neighbors) – Experimental ¡design ¡can ¡be ¡just ¡as ¡important ¡as ¡the ¡ learning ¡algorithm ¡itself

  • Function ¡Approximation ¡View

– Assumption: ¡inputs ¡are ¡sampled ¡from ¡some ¡ unknown ¡distributions – Assumption: ¡outputs ¡come ¡from ¡a ¡fixed ¡unknown ¡ function ¡(e.g. ¡human ¡annotator) – Goal: ¡Learn ¡a ¡hypothesis ¡which ¡closely ¡ approximates ¡that ¡function

65