Skip to main content

Posts

Showing posts with the label K-Nearest-Neighbors-Algorithm

What is K-Nearest Neighbors algorithm

K-Nearest Neighbors Algorithm Concepts of K-Nearest Neighbors K-Nearest Neighbors (KNN) is a non-parametric classification algorithm that works on the principle of identifying the K number of nearest neighbours of a data point in the training set and predicting its class based on the majority class of its K nearest neighbours. The value of K is a hyperparameter that needs to be optimized based on the dataset. Here is an example of how KNN works : Suppose we have a dataset of different fruits categorized into apples, oranges, and bananas based on their weight and size. We want to classify a new fruit based on its weight and size. We choose a value of K, say K=3. We calculate the Euclidean distance between the new fruit and all the existing fruits in the dataset. We select the 3 nearest neighbours and count the number of apples, oranges, and bananas among the 3 neighbours. The class with the highest count is assigned to the new fruit. K-Nearest Neighbors Algorithm Define the problem and