KNN algorithm simple explanation with code

KNN ALGORITHM K nearest neighbor is a supervised machine learning algorithm that is non parametric(has no underlying assumptions). KNN is usually used for regression and classification (mostly used for classification) KNN is a lazy algorithm as it uses all the training data inorder to classify new data points this may lead to excessive use of computer memory. Although there are many clustering algorithm it is usually better to learn KNN first to provide a basis for more complex algorithms. KNN can lead to overfitting if a small value is chosen for k and underfitting if a large value is used for k. It is usually relevant to select an odd number for the value of k to reduce instances where some points are left out during clustering. Dataset that has most outliers is usually classified welll if a large k value is chosen. K is the neighbor to which distance is calculated from training data points to ...