---
title: "K-nearest neighbor on student table"
subject: "Data Mining"
chapter: 3
key: "semester_7/data_mining:knn-student-weights"
source: https://www.bctengineer.com/q/semester_7/data_mining/knn-student-weights
site: BCT Engineering
---

# K-nearest neighbor on student table

Data Mining · Chapter 3: Classification

- Asked in: year not given, 2+10 marks
- Video: [K-Nearest Neighbor Classification ll KNN Classification Explained with Solved Example in Hindi](https://www.youtube.com/watch?v=CJjSPCslxqQ) — 5 Minutes Engineering
- Answer checked by Claude Opus 5.5 (high effort) on 2026-10-14
- Page: https://www.bctengineer.com/q/semester_7/data_mining/knn-student-weights
- Whole chapter: https://www.bctengineer.com/md/semester_7/data_mining/chapter-3

## Question

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).

| Name | Age | Weight |
| --- | --- | --- |
| Std1 | 22 | 53 |
| Std2 | 26 | 57 |
| Std3 | 20 | 54 |
| Std4 | 24 | 52 |

## 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.

## Answer

#### 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) | Calculation | Distance to Std1 |
| --- | --- | --- | --- |
| Std2 | (26, 57) | √(4² + 4²) = √32 | 5.657 |
| Std3 | (20, 54) | √(2² + 1²) = √5 | 2.236 |
| Std4 | (24, 52) | √(2² + 1²) = √5 | 2.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:

| | Std1 | Std2 | Std3 | Std4 |
| --- | --- | --- | --- | --- |
| Std1 | 0 | 5.657 | 2.236 | 2.236 |
| Std2 | 5.657 | 0 | 6.708 | 5.385 |
| Std3 | 2.236 | 6.708 | 0 | 4.472 |
| Std4 | 2.236 | 5.385 | 4.472 | 0 |

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.

## Check yourself

The answer's key points as multiple-choice questions, with the correct option and why.

1. KNN is described as:
   A. An eager rule learner
   B. A neural network
   C. A lazy, instance-based classifier
   D. A tree-building algorithm
   Answer: C. It stores instances and computes distances at classification time. (Key point: KNN nature)

2. Distance from Std1 (22,53) to Std3 (20,54) is:
   A. sqrt(32) = 5.657
   B. sqrt(3) = 1.73
   C. sqrt(10) = 3.16
   D. sqrt(5) = 2.236
   Answer: D. sqrt(2^2 + 1^2). (Key point: Distance Std1-Std3)

3. Which two students are nearest to Std1?
   A. Std3 and Std4
   B. Std2 and Std3
   C. Std2 and Std4
   D. Std2 only
   Answer: A. Std3 and Std4 are both at 2.236; Std2 is at 5.657. (Key point: Nearest two)

4. Why was normalisation not needed here?
   A. Distances were zero
   B. Age and weight have similar ranges
   C. Only one attribute was used
   D. KNN never needs it
   Answer: B. Normalisation matters when ranges differ widely. (Key point: Normalisation)

## Related in Data Mining

- [DM techniques; likelihood and distance principle](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Adm-techniques-close-data-alike) — Data Mining, chapter 3
- [Rote-learner and K-nearest neighbor](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Arote-learner-knn) — Data Mining, chapter 3
- ["Do as your Neighbor Do" principle](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Aneighbor-do-likelihood-distance) — Data Mining, chapter 3
- [Short note: Likelihood and distance](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Alikelihood-distance-note) — Data Mining, chapter 3
- [Likelihood and distance; K-means drawbacks](https://www.bctengineer.com/question.md?key=semester_7%2Fdata_mining%3Alikelihood-distance-clustering-kmeans-drawbacks) — Data Mining, chapter 3

## Related in other subjects

- [96 students record; pass marks](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Afile-96-students-ioe-txt) — Computer Programming, chapter 10
- [Student records with two functions](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Astruct-student-read-display-functions) — Computer Programming, chapter 8
- [Pass student array; display passed students](https://www.bctengineer.com/question.md?key=semester_1%2Fcomputer_programming%3Apass-whole-array-student-info) — Computer Programming, chapter 7
- [Mat 18 m × 22 m, safe building weight](https://www.bctengineer.com/question.md?key=semester_5%2Ffoundation_engineering%3Amat-18x22-clay-ucs75) — Foundation Engineering, chapter 7, asked 2×
