0% found this document useful (0 votes)
150 views

KNN Solved Example

Uploaded by

umknriyaown123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
150 views

KNN Solved Example

Uploaded by

umknriyaown123
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

kNN solved Example

kNN solved Example


Given Data

Height (in cms) Weight (in kgs) T Shirt Size


158 58 M
New observation 161cm and weight 61kg.
158 59 M What is the T-shirt size?
158 63 M
160 59 M
160 60 M
163 60 M
Use : k=3 and k=5
163 61 M
160 64 L
163 64 L
165 61 L
165 62 L
165 65 L
168 62 L
168 63 L
168 66 L
170 63 L
170 64 L
170 68 L
kNN solved Example
Step 1: Calculate Euclidean distance between existing observation and new observation
New x=161 y=61
x y
Height Weight T Shirt Distance
(in cms) (in kgs) Size (Xi,Yi)
158 58 M Sqrt(161-158)^+(61-58)^2) 4.24
158 59 M Sqrt(161-158)^+(61-59)^2) 3.61
158 63 M Sqrt(161-158)^+(61-63)^2) 3.61
160 59 M Sqrt(161-160)^+(61-59)^2) 2.24
160 60 M Sqrt(161-160)^+(61-60)^2) 1.41
163 60 M Sqrt(161-163)^+(61-60)^2) 2.24
163 61 M Sqrt(161-163)^+(61-61)^2) 2.00
160 64 L Sqrt(161-160)^+(61-64)^2) 3.16
163 64 L Sqrt(161-163)^+(61-64)^2) 3.61
165 61 L Sqrt(161-165)^+(61-61)^2) 4.00
165 62 L Sqrt(161-165)^+(61-62)^2) 4.12
165 65 L Sqrt(161-165)^+(61-65)^2) 5.66
168 62 L Sqrt(161-168)^+(61-62)^2) 7.07
168 63 L Sqrt(161-168)^+(61-63)^2) 7.28
168 66 L Sqrt(161-168)^+(61-66)^2) 8.60
170 63 L Sqrt(161-170)^+(61-63)^2) 9.22
170 64 L Sqrt(161-170)^+(61-64)^2) 9.49
170 68 L Sqrt(161-170)^+(61-68)^2) 11.40
kNN solved Example
Step 2 : Find K-Nearest Neighbors
New x=161 y=61
x y
He ight We ight T Shirt Dista nc e C lose d
(in c ms) (in kgs) Siz e (Xi,Yi) Ne ighbors
158 58 M 4.24
158 59 M 3.61
158 63 M 3.61
160 59 M 2.24 3
160 60 M 1.41 1
163 60 M 2.24 4
163 61 M 2.00 2
160 64 L 3.16 5
163 64 L 3.61
165 61 L 4.00
165 62 L 4.12
165 65 L 5.66
168 62 L 7.07
168 63 L 7.28
168 66 L 8.60
170 63 L 9.22
170 64 L 9.49
170 68 L 11.40
kNN solved Example

• 'Medium T-shirt size' is in blue color and 'Large T-shirt size' in orange color. New customer information
is exhibited in the yellow circle.

• Four blue highlighted data points, and one orange highlighted data points close the yellow circle.

• So. the prediction for the new case is a blue highlighted data point: Medium T-shirt size (for both k=3
and k=5).
kNN solved Example 2

Weight Height Class 1. Classify new observation Weight =59 and Height =170?
51 167 Underweight (k=3)
62 182 Normal Weight Height Class Distance
63 176 Normal 51 167 Underweight 8.54
65 173 Normal 62 182 Normal 12.37
63 176 Normal 7.21
68 172 Normal
65 173 Normal 6.71
55 174 Normal 68 172 Normal 9.22
52 169 Normal 55 174 Normal 5.66 3
56 173 Underweight 52 169 Normal 7.07
56 173 Underweight 2
57 170 Normal 4.24
1
57 170 Normal 2.00
61 181 Normal
61 181 Normal 11.18

• So. the prediction for the new case is: Normal (for both k=3).

You might also like