n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E...
Transcript of n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E...
![Page 1: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/1.jpg)
Classi�cation withnearest neighbors
S U P E R V I S E D L E A R N I N G I N R : C L A S S I F I C AT I O N
Brett LantzInstructor
![Page 2: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/2.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Classi�cation tasks for driverless cars
![Page 3: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/3.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Understanding Nearest Neighbors
![Page 4: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/4.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Measuring similarity with distance
![Page 5: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/5.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Applying nearest neighbors in Rlibrary(class)
pred <- knn(training_data, testing_data, training_labels)
![Page 6: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/6.jpg)
Let's practice!S U P E R V I S E D L E A R N I N G I N R : C L A S S I F I C AT I O N
![Page 7: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/7.jpg)
What about the 'k' inkNN?
S U P E R V I S E D L E A R N I N G I N R : C L A S S I F I C AT I O N
Brett LantzInstructor
![Page 8: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/8.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Choosing 'k' neighbors
![Page 9: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/9.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Bigger 'k' is not always better
![Page 10: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/10.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Choosing 'k'
![Page 11: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/11.jpg)
Let's practice!S U P E R V I S E D L E A R N I N G I N R : C L A S S I F I C AT I O N
![Page 12: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/12.jpg)
Data preparation forkNN
S U P E R V I S E D L E A R N I N G I N R : C L A S S I F I C AT I O N
Brett LantzInstructor
![Page 13: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/13.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
kNN assumes numeric data
![Page 14: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/14.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
kNN bene�ts from normalized data
![Page 15: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/15.jpg)
SUPERVISED LEARNING IN R: CLASSIFICATION
Normalizing data in R# define a min-max normalize() function normalize <- function(x) { return((x - min(x)) / (max(x) - min(x)))}
# normalized version of r1 summary(normalize(signs$r1))
Min. 1st Qu. Median Mean 3rd Qu. Max. 0.0000 0.1935 0.3528 0.4046 0.6129 1.0000
# un-normalized version of r1summary(signs$r1)
Min. 1st Qu. Median Mean 3rd Qu. Max. 3.0 51.0 90.5 103.3 155.0 251.0
![Page 16: n ea rest n ei g h b o rs C l a ssi ca ti o n w i th...Unders ta ndi ng Nea res t Nei g hbors SU P E R V I SE D LE A R NI NG I N R : CLA SSI F I CATI O N M ea s uri ng s i m i l a](https://reader034.fdocuments.us/reader034/viewer/2022042306/5ed20f819eb0885e0304a1bd/html5/thumbnails/16.jpg)
Let's practice!S U P E R V I S E D L E A R N I N G I N R : C L A S S I F I C AT I O N