CSC 411: Lecture 05: Nearest Neighbors
Class based on Raquel Urtasun & Rich Zemel’s lectures Sanja Fidler
University of Toronto
Jan 25, 2016
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 1 / 21
CSC 411: Lecture 05: Nearest Neighbors Class based on Raquel Urtasun - - PowerPoint PPT Presentation
CSC 411: Lecture 05: Nearest Neighbors Class based on Raquel Urtasun & Rich Zemels lectures Sanja Fidler University of Toronto Jan 25, 2016 Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 1 / 21 Today
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 1 / 21
◮ distance ◮ non-linear decision boundaries
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 2 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 3 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 4 / 21
◮ It puts non-identical things in the same class, so a difference in the
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 5 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 6 / 21
◮ Output varies smoothly with input ◮ Data occupies sub-space of high-dimensional input space Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 7 / 21
j
j
x(i)∈train. set
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 8 / 21
◮ show how input space divided into classes ◮ each line segment is equidistant between two points of opposite classes Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 9 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 10 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 11 / 21
[Pic by Olga Veksler]
t(z) k
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 12 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 13 / 21
◮ normalize scale ◮ Simple option: Linearly scale the range of each feature to be, eg, in
◮ Linearly scale each dimension to have 0 mean and variance 1 (compute
◮ be careful: sometimes scale matters
◮ eliminate some attributes ◮ or vary and possibly adapt weight of attributes
◮ Hamming distance Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 14 / 21
◮ Use subset of dimensions ◮ Pre-sort training examples into fast data structures (kd-trees) ◮ Compute only an approximate distance (LSH) ◮ Remove redundant data (condensing)
◮ Remove redundant data (condensing) ◮ Pre-sorting often increases the storage requirements
◮ Required amount of training data increases exponentially with
◮ Computational cost also increases dramatically
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 15 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 16 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 17 / 21
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 18 / 21
◮ Get 6M images from Flickr with gps info (dense sampling across world) ◮ Represent each image with meaningful features ◮ Do kNN!
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 19 / 21
◮ Get 6M images from Flickr with gps info (dense sampling across world) ◮ Represent each image with meaningful features ◮ Do kNN (large k better, they use k = 120)!
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 20 / 21
◮ Sensitive to class noise. ◮ Sensitive to scales of attributes. ◮ Distances are less meaningful in high dimensions ◮ Scales linearly with number of examples
Urtasun, Zemel, Fidler (UofT) CSC 411: 05-Nearest Neighbors Jan 25, 2016 21 / 21