You are on page 1of 12

MEL G622 Introduction to ANN

Course Instructor:Dr.V.Kalaichelvi.,
BITS Pilani
Associate Professor/EEE
Dubai Campus
BITS Pilani
Dubai Campus

KNN CLASSIFIER
Check Points

https://www.youtube.com/watch?v=Jwo5Ae7tH_I

https://www.youtube.com/watch?v=Jwo5Ae7tH _I

VLOOKUP Refer above link


In ADD INS check for Analysis ToolPAK is added or not

https://www.youtube.com/watch?v=reuU2zUsEPM

BITS Pilani, Dubai Campus


KNN Classifier

 A super simple way to


classify data

 KNN stores all available


cases and classifies new
cases based on a
similarity Measure

 Step 1: Start with data set


with known categories
 we have different data
sets from intestinal tumor

BITS Pilani, Dubai Campus


KNN Classifier

Step 1
 K nearest neighbor is
equal to 1.
 Use the category
which is nearest to
the neighbor
 In this case its equal
to GREEN

BITS Pilani, Dubai Campus


KNN Classifier Contd..

Step 2
 Add a new cell with
unknown category

 The data has been


taken from another
tumor

BITS Pilani, Dubai Campus


KNN Classifier Contd..

Step 3
 Classify the new cell
by looking at the
new cell with
unknown category

BITS Pilani, Dubai Campus


KNN Classifier Contd..

Step 4
 K=11, the new cell
will be closer
between two or more
categories

 Choose the category


that gets more votes

BITS Pilani, Dubai Campus


KNN Classifier Contd..

Step 5

 7 Nearest neighbors
are Red
 3 Nearest neighbors
are Orange
 1 nearest neighbor is
Green

BITS Pilani, Dubai Campus


Procedure for KNN Classifier

 1.Load data (xls file)

 2.Initialize K(nearest neighbors k=1,3,5,7 odd no trials


will be better for similarity)

 3.For each sample in the training data do the following


steps
 3.1 Find the distance between querry point and current
point (Eucledean Distance)

BITS Pilani, Dubai Campus


Procedure for KNN Classifier

 3.2 Sort ordered collection of distanceand


indexes from small to Large. (Ascending
Order)

 4. Pick first k entries from sorted collection

 5.Get the labels of selected K entries

BITS Pilani, Dubai Campus


KNN Classifier in Excel

Sepal Width Sepal Length Species


3.7 5.3Setosa
 Eucledean
3.8
3
5.1Setosa
7.2Virginica Distance=SQRT((A2-
3.4 5.4Setosa
3.3
3.9
5.1Setosa
5.4Setosa
$A$23)^2+(B2-
2.8
2.8
7.4virginica
6.1Versicolor
$B$23)^2)
2.9 7.3Virginica
2.7 6Versicolor
2.8 5.8virginica

 =RANK(O2,$O$2:$O
2.3 6.3Versicolor
2.5 5.1Versicolor
2.5 6.3Versicolor
2.4 5.5Versicolor
$16,1)
 =VLOOKUP(Q2,$N$
2:$P$16,3,FALSE)
3.1 5.2

BITS Pilani, Dubai Campus

You might also like