This is because in large datasets the cost of calculating distance between new point and each existing point becomes higher. The KNN algorithm has a high prediction cost for large datasets.The KNN algorithm doesn't work well with high dimensional data because with large number of dimensions, it becomes difficult for the algorithm to calculate distance in each dimension.the value of K and the distance function (e.g. There are only two parameters required to implement KNN i.e.Since the algorithm requires no training before making predictions, new data can be added seamlessly.This makes the KNN algorithm much faster than other algorithms that require training e.g SVM, linear regression, etc. As said earlier, it is lazy learning algorithm and therefore requires no training prior to making real time predictions.In this section we'll present some of the pros and cons of using the KNN algorithm. Therefore the new data point will be classified as "Red". From the figure above we can see that the two of the three nearest points belong to the class "Red" while one belongs to the class "Blue". The final step of the KNN algorithm is to assign new point to the class to which majority of the three nearest points belong. Suppose you have a dataset with two variables, which when plotted, looks like the one in the following figure. Let's see this algorithm in action with the help of a simple example. Finally it assigns the data point to the class to which the majority of the K data points belong. It then selects the K-nearest data points, where K can be any integer. The distance can be of any type e.g Euclidean or Manhattan etc. It simply calculates the distance of a new data point to all other training data points. The intuition behind the KNN algorithm is one of the simplest of all the supervised machine learning algorithms. But before that let's first explore the theory behind KNN and see what are some of the pros and cons of the algorithm. In this article, we will see how KNN can be implemented with Python's Scikit-Learn library. linear-separability, uniform distribution, etc. This is an extremely useful feature since most of the real world data doesn't really follow any theoretical assumption e.g. KNN is a non-parametric learning algorithm, which means that it doesn't assume anything about the underlying data. Rather, it uses all of the data for training while classifying a new data point or instance. It is a lazy learning algorithm since it doesn't have a specialized training phase. KNN is extremely easy to implement in its most basic form, and yet performs quite complex classification tasks. The K-nearest neighbors (KNN) algorithm is a type of supervised machine learning algorithms.