Professional Documents
Culture Documents
Algorithms: K Nearest Neighbors
Algorithms: K Nearest Neighbors
Algorithms: K Nearest Neighbors
Dr. Prafulla Bharat Bafna, Symbiosis Institute of Computer Studies and Research ,
Symbiosis International (Deemed) University
Compute
Distance
Test
Record
Training
Records Choose k of the
“nearest” records
Dr.Prafulla i1
Bharat Bafna, SICSR, 11
9
K-Nearest Neighbor Algorithm
https://www.youtube.com/watch?v=IPqZKn_cMts
&t=22s
• All the instances correspond to points in an n-dimensional
feature space.
$200,000
$150,000
Loan$ Non-Default
$100,000 Default
$50,000
$0
0 10 20 30 40 50 60 70
Age
48 $142,000 ?
D (x x ) 2 ( y y ) 2
1 2
1
2
Dr.Prafulla Bharat Bafna, SICSR, 20
KNN Classification – Standardized Distance
Age Loan Default Distance
0.125 0.11 N 0.7652
0.375 0.21 N 0.5200
0.625 0.31 N 0.3160
0 0.01 0.9245
0.375 0.50 N 0.3428
0.8 0.00 0.6220
0.075 0.38 N 0.6669
0.5 0.22 0.4437
1 0.41 N 0.3650
0.7 1.00 0.3861
0.325 0.65 Y 0.3771
0.7 0.61 Y
X Min
Xs Y
Max
MinBafna,Y SICSR,
Dr.Prafulla Bharat 21
Strengths of KNN
• Very simple and intuitive.
• Can be applied to the data from any distribution.
• Good classification if the number of samples is large enough.
Weaknesses of KNN