Skip to main content

K-nearest neighbor on student table

Short answer

K-nearest neighbor (KNN) is a lazy classifier that finds the K closest training records by distance and assigns the majority class. Using Euclidean distance on Std1 (22,53), the two nearest students are Std3 (20,54) and Std4 (24,52) with distance 2.236 each.

What is K-nearest neighbor? Find the other two students with common behavior from any one record of the following table (apply likelihood and distance principle).

NameAgeWeight
Std12253
Std22657
Std32054
Std42452

K-nearest neighbour (KNN)

KNN is a lazy, instance-based classifier. To classify (or find similar objects for) a new object, it computes the distance to all stored objects, picks the K nearest and assigns the majority class of those neighbours. It rests on the likelihood and distance principle: close objects behave alike.

Solution

Take Std1 = (22, 53) as the given record and find its two nearest students using Euclidean distance d = √[(Age₁ − Age₂)² + (Weight₁ − Weight₂)²]. Here K = 2.

Student(Age, Weight)CalculationDistance to Std1
Std2(26, 57)√(4² + 4²) = √325.657
Std3(20, 54)√(2² + 1²) = √52.236
Std4(24, 52)√(2² + 1²) = √52.236

Sorting by distance: Std3 (2.236) and Std4 (2.236) are nearest; Std2 (5.657) is far.

Answer: the two students with behaviour most common to Std1 are Std3 and Std4.

For completeness, the full distance matrix:

Std1Std2Std3Std4
Std105.6572.2362.236
Std25.65706.7085.385
Std32.2366.70804.472
Std42.2365.3854.4720

Taking another record as the query gives: for Std2 the nearest two are Std4 (5.385) and Std1 (5.657); for Std3 they are Std1 (2.236) and Std4 (4.472); for Std4 they are Std1 (2.236) and Std3 (4.472). Age and weight have similar ranges here, so no normalisation was required.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Data Mining chapter 3 questions →