KNN (K Nearest Neighbors) refers to an algorithm that is generally used in many machine learning applications. Starting from supervised settings to retrieving items in applications, the KNN algorithm can be used for all. It is a part of the supervised learning umbrella and it is considered to be one of the most important algorithms in machine learning. In this article, we will look at the advantages and disadvantages of KNN in Machine Learning.

**What is KNN in Machine Learning?**

KNN is an algorithm used to supervise machine learning. This algorithm has the capability to solve both regression and classification problems of statements. The symbol ‘K’ represents the number of nearest neighbors in terms of an unknown new variable that must be classified or predicted. Unclassified data points are classified by the KNN algorithm subjected to their similarity and proximity to more available data points.

It is widely used to solve problems in a variety of industries due to its convenience, application to regression and classification issues, and the ease with which the results can be generated and interpreted. The algorithm’s fundamental assumption is to gain similar data points which can be established near each other. The main goal of the KNN algorithm is to find all of the nearest neighbors to an unknown new data point to determine the class which it belongs to. It is an approach that is based on distance.

**KNN for Classification:**KNN can be drawn upon for classification in a superintendent setting where datasets that have target labels are provided. KNN selects the ‘K’ which is closest to the data points during the training set for classification. Hence, this leads to the label of the target being computed as the value of the target label is a part of KNN.

**KNN for Regression:**In a supervised situation, where a dataset is given by continuous target values, KNN can be utilized for regression. KNN selects the closest K data point in the training set for regression. This helps in computing the value targeted as the mean of these KKN target values.

**KNN – The Algorithm**

K refers to numerous nearest neighbors. When K is equal to one, this algorithm is the Nearest Neighbor (NN). It is the most basic scene in which, given an unlabeled place X, the algorithm will be able to forecast its label by locating the nearest labeled point to X. After this, the algorithm assigns the point as the label.

The functioning of the algorithm is as follows:

Step 1: Select the no.of K and the distance metric used to determine the proximity

Step 2: Search for the KNN of the point that you want to be classified

Step 3: Allocate the point with a label provided by the majority of the vote

**Advantages of KNN **

Some advantages of KNN in Machine Learning include:

- Simple to understand and put into action.
- When used for regression and classification, it can grasp decisions based on non-linear boundaries. It can devise an extremely flexible decision boundary by varying the ‘K’ value.
- There is no explicit training required in the KNN algorithm, and all the work is done during prediction.
- It is constantly evolving with recent and new data. Due to no clear step in training, the prediction is modified as new data gets added to the dataset. This in turn ensures that there is no retraining of a new model.
- Uses only sole hyperparameters. The ‘K’ value is known to be the only parameter in this algorithm. This in turn facilitates adapting to hyperparameters easily.
- An ideal choice for distance metrics since there are numerous distance metrics to choose from. Some of these metrics include Hamming distance, Minkowski, Manhattan, Euclidean, and other popular distance metrics.

**Disadvantages of KNN**

Some of the disadvantages of KNN are as follows:

- This algorithm can predict complexity for large types of databases. Hence, it is not ideal for huge datasets because each prediction requires the processing of the complete training data. For every prediction, the complexity of rime is O(MNlog(k). Here, M refers to the data dimension and N refers to the number or size of occurrences in the training data. It should be noted that there are ways to specialize and organize data in order to direct attention to the issue and speed up KNN.
- This algorithm even has the power to predict complexity using higher dimensions. In learning which is supervised, the complexity of prediction increases with high-ranking dimensional data. This is in reference to time complexity being dependent on the dimensions.
- KNN assigns equal weight to every feature. As KNN anticipates points to be close to each other in every single dimension, there may be a possibility for it to reject points that are close in some dimensions but far away in others. This can be changed by selecting an appropriate distance measurement. Furthermore, it can turn out to be sensitive if various features have varying ranges. This can be directed by scaling features after preprocessing appropriately.
- It has a certain sensitivity towards outliers. A single incorrectly labeled example can cause the boundaries of the class to shift. This may be more of an issue in a bigger dimension if there is an outline in one of the dimensions. Due to the separation of average in high in the higher dimension, outliers have the capability to create an even bigger and greater impact.

**Conclusion**

In conclusion, kNN is a highly used and simple algorithm in machine learning. It mainly functions through the assignment of labeling an unlabeled point depending on the proximity of the point that is labeled as compared to the closest labeled points.

There are certain advantages and disadvantages to the same as we read in this article. The main advantage of KNN is that it is adaptable in various calculations of proximity, it is based on the approach of memory, and it is extremely instinctive. Whereas, the main disadvantage of KNN is that it is inefficient in terms of computation and it is hard to select the right value of K.

## Leave a Reply