0% found this document useful (0 votes)
29 views8 pages

14 K - Nearest Neighbours

Uploaded by

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

14 K - Nearest Neighbours

Uploaded by

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

K-Nearest Neighbors

K-nearest neighbors
● K-nearest neighbors is known as knn.
● Knn is the simplest algorithm for supervised machine learning.
● Knn stores all the available data and classify the new data points based on similarity.
● It can be used in both task regression and classification.but it usually prefer to use in
classification.
● It is used to find pattern recognition,intrusion detection and data mining.

A wonderful serenity
Why do we need K-NN
K-Nearest Neighbours is a simple algorithm that stores all available data and classifies new cases based on a similarity measure . It classifies
the new data points on the basis of distance .
For Ex ::

Suppose we have two class , class A and Class B .


Class A is yellow in colour and Class B is purple in color
Now New Data point/Class which is red in colour .
So you calculate the distances of your new data with all the others to know
which ones have the smallest distance, so you get 3 (or 6) of the closest data and
check which class that appears most , in the case of the image below, the closest
data to the new data are those that are inside the first circle (inside circle), and
inside this circle there are 3 other data (already classified with yellow), we will
check which is the predominant class in there, look, it’s purple, because there
are 2 purple balls and only 1 yellow, so this new data that before was not
classified, now it will be classified as purple.
K-NN Working
K-NN working can be explanation ;
● Find the value of K i.e. the nearest data points. K can be any integer value
● Calculate the distance between test data and each row of training data with the
help of any of the method like ( Euclidean, Manhattan or Hamming distance ).
But we generally used Euclidean distance
● Now based on the distance value, sort them in ascending order. .
● Now , choose the top K row from the shorted array/data point .
● Then assign the top class/category to the test data point .
● Our model is Ready .
How select the value of K in K-NN ?
○ There is no rule to determine the value of K so we try some random values . To find the best result of it .
○ But the most preferable value of K is 5 .

○ A very low value like K=1 or K=2 ,K=3 may cause of outliers and make noisy our data
○ A large value may good but that may also cause some difficulties .
Advantages of K-NN.
● It is versatile algorithm can be used for regression and classification task.
● It is simple to implement and intuitive to learn .
● Single hyper parameters which makes easy to tune the model.
● No Training time for classification it simples tags the new data entry based on historical data.
● Variety of distance criteria to choose from like euclidean,manhattan and minkowski distance.
Disadvantages of K-NN.
● Knn does not work well with large dataset because calculating the distance among all the data will be very costly,
● Does not work well with high dimensionality of data
● It is very sensitive to noisy data and missing data.
● Data needs to normalized and standardized properly.

* * For implementation refer code file


Thank
You...

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