0% found this document useful (0 votes)
5 views3 pages

K-Nearest Neighbors (KNN)

K-Nearest Neighbors (KNN) is a supervised machine learning algorithm used for classification and regression by predicting outcomes based on the 'k' closest data points. It is a non-parametric, instance-based method that stores the dataset and classifies new data points based on majority voting from nearby neighbors. Choosing the appropriate value of 'k' is crucial, as it affects the model's accuracy and stability, with larger values potentially leading to underfitting.

Uploaded by

swatisharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views3 pages

K-Nearest Neighbors (KNN)

K-Nearest Neighbors (KNN) is a supervised machine learning algorithm used for classification and regression by predicting outcomes based on the 'k' closest data points. It is a non-parametric, instance-based method that stores the dataset and classifies new data points based on majority voting from nearby neighbors. Choosing the appropriate value of 'k' is crucial, as it affects the model's accuracy and stability, with larger values potentially leading to underfitting.

Uploaded by

swatisharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

K-Nearest Neighbors (KNN) is a supervised machine learning algorithm

generally used for classification but can also be used for regression tasks. It
works by finding the "k" closest data points (neighbors) to a given input and
makesa predictions based on the majority class (for classification) or the
average value (for regression). Since KNN makes no assumptions about the
underlying data distribution it makes it a non-parametric and instance-based
learning method.

K-Nearest Neighbors is also called as a lazy learner algorithm because it does


not learn from the training set immediately instead it stores the dataset and at
the time of classification it performs an action on the dataset.
For example, consider the following table of data points containing two
features:

KNN Algorithm working visualization


The new point is classified as Category 2 because most of its closest
neighbors are blue squares. KNN assigns the category based on the majority
of nearby points. The image shows how KNN predicts the category of a new
data point based on its closest neighbours.
●​ The red diamonds represent Category 1 and the blue squares
represent Category 2.
●​ The new data point checks its closest neighbors (circled points).
●​ Since the majority of its closest neighbors are blue squares
(Category 2) KNN predicts the new data point belongs to Category 2.

KNN works by using proximity and majority voting to make predictions.

What is 'K' in K Nearest Neighbour?


In the k-Nearest Neighbours algorithm k is just a number that tells the
algorithm how many nearby points or neighbors to look at when it makes a
decision.
Example: Imagine you're deciding which fruit it is based on its shape and
size. You compare it to fruits you already know.
●​ If k = 3, the algorithm looks at the 3 closest fruits to the new one.
●​ If 2 of those 3 fruits are apples and 1 is a banana, the algorithm says
the new fruit is an apple because most of its neighbors are apples.

How to choose the value of k for KNN Algorithm?

●​ The value of k in KNN decides how many neighbors the algorithm


looks at when making a prediction.
●​ Choosing the right k is important for good results.
●​ If the data has lots of noise or outliers, using a larger k can make the
predictions more stable.
●​ But if k is too large the model may become too simple and miss
important patterns and this is called underfitting.
●​ So k should be picked carefully based on the data.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy