Nearest Neighbor Algorithm Zaffar Ahmed

2,165 views

Published on

Published in: Technology, Business
2 Comments
0 Likes
Statistics
Notes
  • Thanks
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Very helpful
    Thank you Ahmed
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • Be the first to like this

No Downloads
Views
Total views
2,165
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
181
Comments
2
Likes
0
Embeds 0
No embeds

No notes for slide

Nearest Neighbor Algorithm Zaffar Ahmed

  1. 1. Nearest Neighbor Algorithm<br />Zaffar Ahmed Shaikh<br />
  2. 2. Topics<br />Introduction – Memory-based algorithms<br />K-nearest neighbor (KNN) algorithm<br />How KNN works?<br />KNN Example<br />Different types of KNN<br />
  3. 3. Introduction<br /><ul><li>Memory-based algorithms utilize the entire user-item database to generate a prediction. They find a set of users, known as neighbors, that have a history of agreeing with the target user. Once a neighborhood of users is formed, the preferences of neighbors are combined to produce a prediction or top-K recommendation for the active user. </li></li></ul><li>K-nearest neighbor (KNN)<br />The nearest neighbor algorithm measures the distance dE(Xi,Xj)between query points Xi and a set of training samples Xjto classify a new object based on majority of K-nearest neighbor category of Y attributes of training samples. <br />Query point Xi = x1, x2, x3, ……….., xn<br />Training Sample Xj= x1, x2, x3, ……….., xn<br />
  4. 4. How KNN works?<br />Determine K (no of nearest neighbors)<br />Calculate distance (Euclidean, Manhattan)<br />Determine K-minimum distance neighbors<br />Gather category Y values of nearest neighbors <br />Use simple majority of nearest neighbors to predict value of query instance<br />
  5. 5. KNN Example<br />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. <br />
  6. 6. 1. Determine K<br />Determine value of K <br />Suppose K = 3<br />2. Calculate distance<br />Coordinates of query instance are (4,3,3)<br />Coordinates of training instance(1) are (7,2,1)<br />D = SQRT ((7-4)2+(2-3) 2+(1-3) 2) = 3.74165<br />
  7. 7. 2. Calculate distance<br />
  8. 8. 3. Determine K-minimum distance neighbors<br />K = 3<br />
  9. 9. 4. Gather category Y values of nearest neighbors <br />
  10. 10. 5. Use simple majority of nearest neighbors to predict value of query instance<br />Here India has won 2 matches 2 (-) signs and Pakistan has won 1 match 1 (+) sign<br />We conclude that India will win today’s match <br />
  11. 11. Different types of KNN <br />KNN for Classification<br />KNN for Prediction<br />KNN for Smoothing<br />
  12. 12. Thank you<br />

×