1. University MCA (AI/ML) Semester 2
  2. CAB212
  3. Unit 3

CAB212 · Unit 3: Classification

k-nearest neighbours

8 practice questions

Key points

  • Lazy learner: stores data
  • Distance + majority vote
  • Small k -> high variance
  • Scale features; tune k

k-NN is a lazy, instance-based method: there is no training phase beyond storing data. To classify a point, find its k nearest training points (usually by Euclidean distance) and take a majority vote (classification) or average (regression).

Euclidean distance: d = sqrt(sum((a_i - b_i)^2)). Other choices: Manhattan, Minkowski, cosine.

  • Small k: flexible, low bias, high variance (noisy). k = 1 memorizes training data.
  • Large k: smoother, higher bias.
  • Choose odd k for binary problems to avoid ties; tune k with cross-validation.

Worked example: query (0,0); A(1,0) positive, B(0,2) negative, C(3,3) negative. Distances 1, 2, 4.24. k=1 gives positive; k=3 votes +,-,- giving negative.

Costs: prediction is O(n*d) per query, so it is slow on large data; features must be scaled; it suffers in high dimensions (curse of dimensionality).

Exam pitfall: k-NN needs no training time but has expensive prediction.

Try two questions

Question 1 · Tier 1, Recall

k-NN is called a lazy learner because it:

  1. Never makes any predictions
  2. Uses no training data at all
  3. Trains for many epochs before predicting
  4. Defers computation until prediction time
Show the answer

D. It simply stores training data.

Question 2 · Tier 3, Apply

Unscaled features hurt k-NN because:

  1. Large-range features dominate the distance
  2. k-NN relies on gradient descent to fit
  3. k-NN requires all features to be integers
  4. Scaling changes the class labels
Show the answer

A. Distance is not scale invariant.