0% found this document useful (0 votes)
48 views11 pages

KNN Classification

Uploaded by

Ahsan Raza
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)
48 views11 pages

KNN Classification

Uploaded by

Ahsan Raza
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

KNN classification

K-Nearest Neighbour

• It is a classification algorithm.
• The abbreviation KNN stands for “K-Nearest Neighbour”. It is
a supervised machine learning algorithm. The algorithm can be
used to solve both classification and regression problem
statements. The number of nearest neighbors to a new
unknown variable that has to be predicted or classified is
denoted by the symbol 'K’.
• KNN algorithms use data and classify new data points based
on similarity measures (e.g. distance function). The data is
assigned to the class which has the nearest neighbors.
What is KNN clustering algorithm?

• The k-nearest neighbors (KNN) algorithm is a simple,


supervised machine learning algorithm that can be used to
solve both classification and regression problems.
• KNN represents a supervised classification algorithm that
will give new data points accordingly to the k number or the
closest data points, while k-means clustering is an
unsupervised clustering algorithm that gathers and groups
data into k number of clusters.
Euclidean distance
Euclidean distance between two points in Euclidean space is the
length of a line segment between the two points. It can be
calculated from the Cartesian coordinates of the points using the
Pythagorean theorem, therefore occasionally being called the
Pythagorean distance.
Example, k = 3
Name Gender Age Sports
Ali M 32 Football
Moiz M 40 Neither
Zahra F 16 Cricket
Saira F 34 Cricket
Rashid M 55 Neither
Zahid M 40 Cricket
Sara F 20 Neither
Ahmed M 15 Cricket
Tayyaba F 55 Football
Talha M 15 Football
Ayesha F 5 ?
Convert alphabetical data into numeric. For Male = 0 and Female = 1

Name Gender Age Sports


Ali 0 32 Football
Moiz 0 40 Neither
Zahra 1 16 Cricket
Saira 1 34 Cricket
Rashid 0 55 Neither
Zahid 0 40 Cricket
Sara 1 20 Neither
Ahmed 0 15 Cricket
Tayyaba 1 55 Football
Talha 0 15 Football
Ayesha F 5 ?
By using Euclidean distance formula:

D(p, q) = , here we can find the distance between Ayesha and Moiz

= 27.02 distance
Convert alphabetical data into numeric. For Male = 0 and Female = 1

Name Gender Age Distance Sports


Ali 0 32 27.02 Football
Moiz 0 40 35.01 Neither
Zahra 1 16 11 Cricket
Saira 1 34 9 Cricket
Rashid 0 55 50.01 Neither
Zahid 0 40 35.01 Cricket
Sara 1 20 15 Neither
Ahmed 0 15 10 Cricket
Tayyaba 1 55 50 Football
Talha 0 15 10.05 Football
K=3
Check the 3 closest minimum record
• Saira likes cricket
• Ahmad like cricket
• Talha likes football

The most common value is Cricket so Ayesha likes cricket.

You might also like