The training points are A=(1,1) red, B=(2,1) red, C=(4,5) blue, D=(5,4) blue and E=(4,2) blue. Using Euclidean distance, classify the query q=(3,2) with k=1, k=3 and k=5. What does this tell you about the choice of k?

Supervised learning, k-nearest neighbours
Level L2 Elementary. Length Short. Nature Mat Mathematical.

What's being asked

Whether you can run k-NN by hand: compute distances, sort, then take a majority vote.

Key idea

Compute d(q,xi) for each point, sort, and vote among the k nearest. The answer can change with k.

Steps

  1. Distances from q=(3,2): d(q,A)=4+1=2.236, d(q,B)=1+1=1.414, d(q,C)=1+9=3.162, d(q,D)=4+4=2.828, d(q,E)=1+0=1.
  2. Sort: E (1.000) blue, B (1.414) red, A (2.236) red, D (2.828) blue, C (3.162) blue.
  3. k=1 and k=3: for k=1 only E is used, so blue; for k=3 the nearest are E,B,A (1 blue and 2 red), so red.
  4. k=5: all points, 3 blue and 2 red, so blue (the majority of the whole set).
  5. The label flips between k=1, 3 and 5 because the query sits between the clusters. So k matters, and should be chosen by cross-validation. Note also that k=n always returns the global majority.

Common mistakes

How long your answer should be

A small table and 5 lines.

Read this

Previous in Supervised learning: A 3-class classifier may also reject (refuse to decide). A wrong decision costs 1, a correct decision costs 0, and rejecting costs λr=0.2. For the posteriors (0.55,0.30,0.15) and (0.85,0.10,0.05), what should the classifier do? What is the general rule in terms of λr?
Next in Supervised learning: A multinomial naive Bayes spam filter uses the vocabulary {win,cash,meeting}. Training: spam documents "win win cash" and "cash cash"; ham documents "meeting win" and "meeting meeting cash". Using Laplace (add-one) smoothing, classify the new document "win meeting meeting". Why is the smoothing needed?