KNN Algorithm:
K-Nearest Neighbors is a machine learning algorithm which is used for classification and regression tasks. In this algorithm an object is classified or its value is predicted based on the average of its K nearest neighbors in the feature space, Here K represents the number of neighbors to be considered to make a decision/prediction.
For example, if you have a new Friend and you want to gift him a latest video game, instead of directly asking him whether he likes video games or not, we decide by asking the people around him or his other friends close to him, thinking that if most of their neighbors are into video games, the new friend is also very likely too.
Steps involved in the KNN Algorithm:
Determining the K Value: At first the K value is determined, which is the number of neighbors to be considered when classifying a new data point. This is the most important step as it effects the performance of the algorithm. Chances of overfitting is high when there is a high value for the K and the low value for K may introduce underfitting.
Data Preparation: The data pre processing steps is performed before applying the KNN Algorithm. The data preprocessing steps include handling missing values, removing the inconsistencies and standardizing the data.
Distance Calculation: for each new data point, calculate the distance to each training data point, common distance metrics include Euclidean distance and Manhattan Distance.
K nearest neighbors: The calculated distances are sorted in the ascending order and the K nearest neighbors are selected based on the sorted distances.
Determining the class: The new data point is assigned to the class which is most prevalent among its K nearest neighbors.
Applications of KNN Algorithm :
Medical Diagnosis
Recommender Systems
Spam Filtering
Image Classification