Introduction To Classification - KNN
Introduction To Classification - KNN
CLASSIFICATION
K - NEAREST NEIGHBOUR
Prepared By
Fariha Jahan
Lecturer, Department
of Computer Science &
Engineering
Daffodil International
University(DIU)
Nearest Neighbour
• Mainly used when all attribute values are continuous
• It can be modified to deal with categorical attributes
• The idea is to estimate the classification of an unseen instance
using the classification of the instance or instances that are closest
to it, in some sense that we need to define (classifies new cases
based on a similarity measure)
Nearest Neighbour
• Hamming Distance …
Distance Measures: Euclidean
Distance
• Ifwe denote an instance in the training set by (a1, a2) and the
unseen instance by (b1, b2) the length of the straight line joining
the points is
• Ifthere are two points (a1, a2, a3) and (b1, b2, b3) in a three-
dimensional space the corresponding formula is
48 142000 ??
Age Loan Default Distance
Exercise-1 25 40000 N 102000
35 60000 N 82000
45 80000 N 62000
20 20000 N 122000
35 120000 N 22000
52 18000 N 124000
23 95000 Y 47000
40 62000 Y 80000
60 100000 Y 42000
48 220000 Y 78000
33 150000 Y 8000
48 142000 ??
Age Loan Default Distance
Exercise-2 0.125 0.11 N
0.375 0.21 N
0.625 0.31 N
0 0.01 N
0.375 0.5 N
0.8 0 N
0.075 0.38 Y
0.5 0.22 Y
1 0.41 Y
0.7 1 Y
0.325 0.65 Y
0.7 0.61 ??
Age Loan Default Distance
Exercise-2 0.125 0.11 N 0.762
0.375 0.21 N 0.5154
0.625 0.31 N 0.3092
0 0.01 N 0.922
0.375 0.5 N 0.3431
0.8 0 N 0.6181
0.075 0.38 Y 0.666
0.5 0.22 Y 0.4383
1 0.41 Y 0.3606
0.7 1 Y 0.39
0.325 0.65 Y 0.3771
0.7 0.61 ??