Professional Documents
Culture Documents
Classification - KNN
Classification - KNN
Manh-Hung Ha ISVNU
2. K-Nearest Neighbor – Intuition (KNN)
Problem
Given two classes A, B and a new data point x. Which’ class the point x belong to?
Manh-Hung Ha ISVNU
2. K-Nearest Neighbor – Intuition (KNN)
Problem
Given two classes A, B and a new data point x. Which’ class the point x belong to?
1-NN Distance??
d3
d1
d2
Manh-Hung Ha ISVNU
2. K-Nearest Neighbor – Intuition (KNN)
Problem
Given two classes A, B and a new data point x. Which’ class the point x belong to?
5-NN
• Totally 5 neighbors
• 2 neighbors in class B
• 3 neighbors in class A
• New data point x belong to class A
Manh-Hung Ha ISVNU
3. KNN algorithm
Algorithm
Given multiples classes and a new data point x. Which’s class the point x belong to?
• Select the number K of the neighbors
• Calculate the distance of K number of neighbors
• Take the K nearest neighbors as per the calculated distance.
• Among these K neighbors, count the number of the data points in each category.
• Assign the new data points to that category for which the number of the neighbor is maximum.
Trial test: K = 1, 2, … N
How to find K?
Find K with the best accuracy
Manh-Hung Ha ISVNU
3. KNN algorithm
Algorithm
Manh-Hung Ha ISVNU
4. Conclusions
Manh-Hung Ha ISVNU