Instance Based Learning
Instance Based Learning
3
KNN: Classification Approach
• An object (a new instance) is classified
by a majority votes for its neighbor
classes.
• The object is assigned to the most common
class amongst its K nearest neighbors.
(measured by a distant function )
4
Distance measure for Continuous
Variables
5
Distance Between Neighbors
• Calculate the distance between new example
(E) and all examples in the training set.
8
How to choose K?
9
10
X X X
11
KNN Feature Weighting
13
KNN Classification – Distance
Age Loan Default Distance
25 $40,000 N 102000
35 $60,000 N 82000
45 $80,000 N 62000
20 $20,000 N 122000
35 $120,000 N 22000
52 $18,000 N 124000
23 $95,000 Y 47000
40 $62,000 Y 80000
60 $100,000 Y 42000
48 $220,000 Y 78000
33 $150,000 Y 8000
48
D = $142,000
(x − x )?2 + ( y − y
)2
1 2 1 2 14
KNN Classification
$250,00
0
$200,00
0
Loan Non-
$150,00
$ 0
$100,00 Default
0 Default
$50,00
0
$0 0 1 2 3 4 5 6 7
0 0 0 0 0 0 0
Ag
e
15
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
16