Six points on a line are 1, 2, 3, 10, 11 and 12. Using a flat kernel of radius 2.5 (all points within distance 2.5 get equal weight), run mean shift by hand from the starting positions x=4 and x=9. Where does each run stop, and what do you learn about the number of clusters?

Unsupervised learning, Mean shift
Level L2 Elementary. Length Medium. Nature Mat Mathematical.

What's being asked

Whether you can run the mean-shift iteration x← mean of neighbours and see that it climbs to density modes without being told k.

Key idea

Mean shift moves a point to the mean of the data inside its window: x←∑iK(xi−x) xi∑iK(xi−x). With a flat kernel this is the plain average of the points within the radius. The shift always points uphill on the kernel density estimate, so the runs stop at its modes.

Steps

  1. Set up: the data are 1, 2, 3, 10, 11, 12. With a flat kernel, a point is in the window if its distance from x is at most 2.5.
  2. Start at x=4. Points within 2.5 are those in [1.5,6.5], namely 2 and 3. Their mean is 2.5. New position: 2.5.
  3. From x=2.5 the window is [0,5] and contains 1, 2, 3. Their mean is 2. New position: 2.
  4. From x=2 the window is [−0.5,4.5] and again contains 1, 2, 3. The mean is 2, so the shift is zero. The run has converged at the mode x=2.
  5. Start at x=9. The window [6.5,11.5] contains 10 and 11, mean 10.5. From 10.5 the window [8,13] contains 10, 11, 12, mean 11. From 11 the window [8.5,13.5] contains 10, 11, 12 again, mean 11. It converges at x=11.
  6. Every start near 1–3 ends at 2 and every start near 10–12 ends at 11. So there are two modes and two clusters. Points are labelled by the mode they reach, and k was never supplied. The radius (bandwidth) controls how many modes appear.

Common mistakes

How long your answer should be

Half a page with the sequence of positions; 3–4 minutes.

Last checked on 4 December 2026.

Read this

Previous in Unsupervised learning: Five shopping baskets are T1 = {A, B, C}, T2 = {A, B}, T3 = {A, C}, T4 = {B, C, D} and T5 = {A, B, C, D}. Run Apriori with minimum support count 2 to list all frequent itemsets. Then, for the rules {A,B}→C and {B,C}→D, compute confidence and lift. Which rule shows a real association?
Next in Unsupervised learning: How do you derive PCA as finding the direction of maximum variance?