Lecture 2:
−Nearest Neighbour Classifier
Aykut Erdem
September 2017 Hacettepe University
Lecture 2: Nearest Neighbour Classifier Aykut Erdem September 2017 - - PowerPoint PPT Presentation
Lecture 2: Nearest Neighbour Classifier Aykut Erdem September 2017 Hacettepe University Your 1st Classifier: Nearest Neighbor Classifier Concept Learning Definition: Acquire an operational definition of a general category of objects
Aykut Erdem
September 2017 Hacettepe University
3
slide by Thorsten Joachims
attributes (often called features).
membership in c based on attributes (i.e. label) (f is unknown).
4
correct (3) color (2)
(2) presentation (3) binder (2) A+ complete yes yes clear no yes complete no yes clear no yes partial yes no unclear no no complete yes yes clear yes yes correct
(complete, partial, guessing)
color
(yes, no)
(yes, no)
presentation
(clear, unclear, cryptic)
binder
(yes, no)
A+ 1 complete yes yes clear no yes 2 complete no yes clear no yes 3 partial yes no unclear no no 4 complete yes yes clear yes yes
slide by Thorsten Joachims
– Learn (to imitate) a function f : X → {+1,-1}
– Learning algorithm is given the correct value of the function for particular inputs → training examples – An example is a pair (x, y), where x is the input and y = f(x) is the output of the target function applied to x.
– Find a function h: X → {+1,-1} that approximates f: X → {+1,-1} as well as possible.
5
slide by Thorsten Joachims
6
– Learn (to imitate) a function f : X → Y
– Learning algorithm is given the correct value of the function for particular inputs → training examples – An example is a pair (x, f (x)), where x is the input and y = f (x) is the output of the target function applied to x.
– Find a function h: X → Y that approximates f: X → Y as well as possible.
slide by Thorsten Joachims
7
slide by Thorsten Joachims
8
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
9
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
10
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
11
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
12
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
13
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
14
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
15
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
16
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
17
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
18
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
Data-driven approach: 1.Collect a dataset of images and labels 2.Use Machine Learning to train an image classifier 3.Evaluate the classifier on a withheld set of test images
19
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
Remember all training images and their labels Predict the label of the most similar training image
20
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
21
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
22
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
23
Lecture 2 - 6 Jan 2016 Lecture 2 - 6 Jan 2016 24
Nearest Neighbor classifier
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
24
Lecture 2 - 6 Jan 2016 Lecture 2 - 6 Jan 2016 25 remember the training data Nearest Neighbor classifier
25
Lecture 2 - 6 Jan 2016 Lecture 2 - 6 Jan 2016 26
for every test image:
image with L1 distance
image
Nearest Neighbor classifier
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
26
Lecture 2 - 6 Jan 2016 Lecture 2 - 6 Jan 2016 27 Q: how does the classification speed depend
the training data? Nearest Neighbor classifier
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
27
Lecture 2 - 6 Jan 2016 Lecture 2 - 6 Jan 2016 28 Q: how does the classification speed depend
training data? linearly :( Nearest Neighbor classifier
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
28
Lecture 2 - 6 Jan 2016 Lecture 2 - 6 Jan 2016 29
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
29
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
30
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
31
32
– Attribute vectors: !# ∈ $ – Labels: "# ∈ %
– Similarity function: & ∶ $ × $ → R – Number of nearest neighbors to consider: k
– New example !′ – K-nearest neighbors: k train examples with largest &(!#, !′)
⃗, 𝑧 , … , x, 𝑧 )
– 𝑦 ⃗ ∈ 𝑌 – 𝑧 ∈ 𝑍
𝐿 ∶ 𝑌 × 𝑌 ¡ → ¡ℜ –
x’ – 𝐿(𝑦 ⃗, 𝑦 ⃗)
slide by Thorsten Joachims
33
slide by Thorsten Joachims
34
slide by Thorsten Joachims
35
slide by Thorsten Joachims
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
36
slide by Fei-Fei Li & Andrej Karpathy & Justin Johnson
37
38
39
40
– Attribute vectors: !# ∈ $ – Target attribute "# ∈ %
– Similarity function: & ∶ $ × $ → R – Number of nearest neighbors to consider: k
– New example !′ – K-nearest neighbors: k train examples with largest &(!#, !′)
⃗, 𝑧 , … , 𝑦 ⃗, 𝑧
– 𝑦 ⃗ ∈ 𝑌 – 𝑧 ∈ 𝑍
𝐿 ∶ 𝑌 × 𝑌 ¡ → ¡ℜ –
x’ – 𝐿 𝑦 ⃗, 𝑦 ⃗
41
42
A nearest neighbor recognition example
slide by James Hays
43
slide by James Hays
44
slide by James Hays
Annotated by Flickr users
slide by James Hays
45
Annotated by Flickr users
slide by James Hays
46
47
slide by James Hays
47
48
slide by James Hays
slide by James Hays
49
50
slide by James Hays
slide by James Hays
51
52
slide by James Hays
slide by James Hays
53
54
slide by James Hays
55
slide by James Hays
56
… 200 total
Hays and Efros, SIGGRAPH 2007 slide by James Hays
57
Hays and Efros, SIGGRAPH 2007 slide by James Hays
58
Graph cut + Poisson blending
Hays and Efros, SIGGRAPH 2007 slide by James Hays
58
59
Hays and Efros, SIGGRAPH 2007 slide by James Hays
60
Hays and Efros, SIGGRAPH 2007 slide by James Hays
61
Hays and Efros, SIGGRAPH 2007 slide by James Hays
62
Hays and Efros, SIGGRAPH 2007 slide by James Hays
63
Hays and Efros, SIGGRAPH 2007 slide by James Hays
64
Hays and Efros, SIGGRAPH 2007 slide by James Hays
65
slide by Thorsten Joachims
1, 𝑧1 , … , 𝑦 𝑜, 𝑧𝑜
– 𝑦 𝑗 ∈ 𝑌 – 𝑧𝑗 ∈ ℜ
𝐿 ∶ 𝑌 × 𝑌 → ℜ –
x’ – 𝐿 𝑦 𝑗, 𝑦 ′
– Attribute vectors: !# ∈ $ – Target attribute "# ∈
– Similarity function: & ∶ $ × $ → – Number of nearest neighbors to consider: k
– New example !′ – K-nearest neighbors: k train examples with largest &(!#,!′)
R R
66
slide by Thorsten Joachims
67
slide by Rob Fergus
68