About kNN

tags: #ML/supervised/classification/knn

What is kNN?

kNN is a supervised algorithm ML algorithm used to perform both classification and regression tasks.

How does kNN work?

Classification Tasks

k-NN works by using proximity of k-number of nearest data points (neighbours) and assigns the label of the majority class to the new data point based on k-number of items with the lowest Euclidean Distance.

Regression Tasks

The algorithm takes the k-nearest values of the target variable and compute the mean of those values.

How do we compute the Euclidean distance of two points?

Suppose two points:

We can compute the Euclidean distance as follows:

d=(x2x1)2+(y2y1)2

In the case of KNN, we will be computing the distance between the new data point and the known data points, assuming there are 2 features (x and y):

d=(xnewx)2+(ynewy)2
Powered by Forestry.md