Lecture 07 KNN 14112022 034756pm
Lecture 07 KNN 14112022 034756pm
Lecture 07 KNN 14112022 034756pm
LECTURER:
Humera Farooq, Ph.D.
Computer Sciences Department,
Bahria University (Karachi Campus)
Outline
2
• Introduction
• Voronoi Diagram
• K-NN Working
• Distance Matric
• K for Neighbors
• Curse-of-Dimensionality
K-Nearest Neighbor
Two classes , Two features
label a new point the same as the closest known
point
Label should be red
Label is red.
What is KNN
4
K nearest neighbors stores all available examples and classifies new example based
on a similarity measure (e.g distance function)
Decrease k:
Allows capturing finer structure of space
Pick k not too large, but not too small (depends on data)
For binary classification problem, use odd value of k.
Reason: Chances of Tie
Missing Data
Average value of the feature
Distance Formula =
Distance (Sepal Length, Sepal Width = = 0.608
Rest All
Example
New Example (K values)
For K = 5
https://medium.com/machine-learning-researcher/k-nearest-neighbors-in-machine-learning-
e794014abd2a