








Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!









Artificial Intelligence
◦ (^) K Nearest Neighbor
◦ (^) Load the data ◦ (^) Determine parameter K = No. of nearest neighbors ◦ (^) Calculate the distance between the query instance and all training samples ◦ (^) Sort the distances in ascending order ◦ (^) Pick the first K entries from the sorted collection ◦ (^) Get the labels of the selected K entries ◦ (^) Use simple majority of the category of the nearest neighbors as the prediction value of the query instance.
◦ (^) One major drawback in calculating distance measures directly from the training set is in the case where variables have different measurement scales ◦ (^) There is a mixture of numerical and categorical variables. ◦ (^) For example, if one variable is based on annual income in dollars, and the other is based on age in years. ◦ (^) In such case income will have a much higher influence on the distance calculated. ◦ (^) One solution is to standardize/normalize the training set.
◦ (^) The algorithm is simple and easy to implement. ◦ (^) There’s no need to build a model, tune several parameters, or make additional assumptions. ◦ (^) The algorithm is versatile. It can be used for classification and search.
◦ (^) Choosing the right K value? ◦ (^) To select the K that’s right for your data, we run the KNN algorithm several times with different values of K and choose the K that reduces the number of errors we encounter while maintaining the algorithm’s ability to accurately make predictions when it’s given data it hasn’t seen before.
◦ (^) Low k-value is sensitive to outliers and a higher K-value is more resilient to outliers as it considers more voters to decide prediction.