kNN is one of many supervised learning algorithms, used in data mining and machine learning. Its is classifier algorithm where the learning in based on how similar is a data from other. kNN can be used for both classification and regression predective problems.
- Load the data.
- Initialize the value of k.
- For getting the predicted classes, iterate from 1 to total numer of training data point.
(i) Calculate distance between test data and each row of training data.
(ii) Sort the calculated distances i ascending order.
(iii) Get the top k rows of the sorted array.
(iv) Get the most frequent class of these rows.
(v) Return the predicted class.
- No assumption about data - useful for non linear data.
- Simple Algortihm.
- High Accuracy.
- Veratile.
- Computationally expensive - because the algorithm stores all the training data.
- High memory requirement.
- Prediction stage might be slow.
- Doesnt works well with large number of features.
- sklearn
- pandas
- numpy