Questions about knn~

楼主: Tonnny (^~^)   2005-03-25 12:18:07
I try to write the knn function by myself instead of using the package.
Thus some detailed about knn should be verified first.
testing set:
5 7 3
training set:
Label C1 C2 C3
A 4 8 9 sqrt( (5-4)^2 + (7-8)^2 + (3-9)^2 ) = sqrt(38)
B 2 6 5 sqrt( (5-2)^2 + (7-6)^2 + (3-5)^2 ) = sqrt(14)
A 6 1 7 sqrt( (5-6)^2 + (7-1)^2 + (3-7)^2 ) = sqrt(53)
B 2 3 5 sqrt( (5-2)^2 + (7-3)^2 + (3-5)^2 ) = sqrt(29)
Therefore, the 1-nearest neighbor is "B".
the 3-nearest neighbor is "B". (B:14,29: vote=2 A:38: vote=1)
Is this procedure correct?
Thanks for answering~

Links booklink

Contact Us: admin [ a t ] ucptt.com