2. Topics Introduction – Memory-based algorithms K-nearest neighbor (KNN) algorithm How KNN works? KNN Example Different types of KNN
3.
4. How KNN works? Determine K (no of nearest neighbors) Calculate distance (Euclidean, Manhattan) Determine K-minimum distance neighbors Gather category Y values of nearest neighbors Use simple majority of nearest neighbors to predict value of query instance
5. KNN Example Predict who will win today’s Cricket match between India and Pakistan based on users rating and previous results of matches played between the two teams.
6. 1. Determine K Determine value of K Suppose K = 3 2. Calculate distance Coordinates of query instance are (4,3,3) Coordinates of training instance(1) are (7,2,1) D = SQRT ((7-4)2+(2-3) 2+(1-3) 2) = 3.74165
10. 5. Use simple majority of nearest neighbors to predict value of query instance Here India has won 2 matches 2 (-) signs and Pakistan has won 1 match 1 (+) sign We conclude that India will win today’s match
11. Different types of KNN KNN for Classification KNN for Prediction KNN for Smoothing