skip to content

What does condensed nearest neighbour remove from a training set, and what does it risk?

level: seniorimportance: nice to knowfreq 16%

answer

  1. shrink the data, not the search
  2. interior points are redundant
  3. the boundary carries the decisions
  4. consistent on the training labels only
  5. noise looks exactly like a boundary point

basics

~10 s

Condensed nearest neighbour keeps a subset that still classifies every original training point correctly under 1-NN. It discards interior points and keeps boundary ones. The risk: mislabelled points are exactly what it preserves.

solid answer

~50 s

The rule builds a subset incrementally: start with one point, sweep the training set classifying each row by 1-NN against the current subset, and add every row the subset gets wrong; repeat the sweep until a full pass adds nothing. What survives are points near the class boundary, because interior points are already covered by neighbours of their own class. A million-row set can collapse to a few thousand prototypes, cutting both query time and the memory footprint proportionally, and the subset is *consistent* — it reproduces the original labels on the original data under 1-NN. The catch is that a noisy or mislabelled point is misclassified by its neighbours, so it is always added, and the reduction therefore concentrates noise. The usual remedy is to run an editing pass first that deletes points their own neighbours disagree with, then condense. The result is also order-dependent and not the smallest possible subset.

go deeper

for a junior

Recall the one-line idea: it keeps the training points near the boundary between classes and throws away the ones buried inside a region where every neighbour already shares their label.

for a middle

Explain the incremental procedure — classify each point against the current subset, add it only when it is wrong, repeat until a pass adds nothing — and state what the resulting subset guarantees about the training data.

for a senior

Demonstrate the operational judgment: edit before condensing, validate on a held-out set that was never part of the reduction, and report the reduction ratio next to the accuracy change.

for a principal

Frame it as a cost-versus-fidelity decision against the alternatives of buying memory or sharding, and set the policy for rebuilding the derived prototype set as labels are corrected and the data moves.

## The problem it solves Exact neighbour search costs `O(n*d)` per query and stores `n*d` values. Trees attack that by skipping candidates. **Prototype selection attacks it from the other end: make `n` smaller.** Condensed nearest neighbour (the CNN rule, Hart 1968) is the classic instance. ## The intuition Under 1-NN, the label a query receives is decided entirely by the decision boundary between classes. A point sitting deep inside a large, pure region of its own class contributes nothing: remove it, and its neighbours of the same class still produce the same label everywhere. A point sitting right against the other class carries the boundary and cannot be removed without moving it. So the useful subset is the boundary points, and everything interior is redundant. ## The algorithm 1. Initialise the subset `S` with a single training point (often the first, or one per class). 2. Sweep the remaining training points. For each point, classify it by 1-NN against `S` only. 3. If the prediction is wrong, move that point into `S`. If it is right, leave it out. 4. Repeat the sweep over the still-excluded points until an entire pass adds nothing. 5. Return `S`, and discard the rest. What `S` gains is the property called **consistency**: run 1-NN with `S` as the stored set over every original training point and you reproduce the original label for all of them. That is a guarantee about the *training* data, not about held-out data — worth stating precisely, because the two get conflated. ## What it buys Because interior mass is exactly what large datasets are made of, the reduction can be dramatic. A million-row training set with well-separated classes can condense to a few thousand boundary prototypes — a three-order-of-magnitude cut in both the per-query scan and the resident memory, with the decision boundary in the interior of the data essentially unchanged. That is the trade that makes it interesting: unlike a faster index, it reduces the *data*, so the savings hit memory and query cost together and hold whatever search implementation you use on top. ## The four things that go wrong **Noise is preserved, not removed.** A mislabelled point is by construction misclassified by its correctly-labelled neighbours, so step 3 always adds it — and once it is in `S`, it also drags in the genuine points around it that it now misclassifies. The rule concentrates exactly the rows you most wanted to lose. The standard fix is to *edit before you condense*: first run an editing pass (the edited nearest-neighbour rule, Wilson 1972) that deletes any training point whose own neighbours disagree with its label, cleaning the boundary, and only then condense the survivors. **It is order-dependent and not minimal.** Sweep the data in a different order and you get a different subset, generally of a different size. CNN finds *a* consistent subset, not the smallest one; finding the minimum is much harder and rarely worth it. **It is built for 1-NN.** The consistency argument is about the single nearest stored point. If you then query with more than one neighbour, the guarantee no longer holds, and the vote is being taken over a set whose local density has been deliberately destroyed. **Density information is gone.** Interior points were removed precisely where a class was dense, so the surviving mixture no longer reflects how much data sat where. Any use of the neighbourhood composition as a confidence or probability estimate becomes unreliable after condensing, even where the hard label is unchanged. ## Using it responsibly Treat condensing as a change to the model and validate it as one. Hold out a genuine test set *before* condensing, condense using training data only, and compare held-out accuracy from the full set against the reduced set — the consistency property says nothing about that number. Record the reduction ratio alongside the accuracy delta, since the entire justification is a cost saving. And keep the original data: the condensed set is a derived artefact you will want to rebuild after an editing pass, after a labelling fix, or when new data shifts the boundary. ## Where it sits There is a family here — editing rules that remove noisy points, condensing rules that remove redundant ones, and hybrids that do both — but the interview-relevant core is the pair of facts: condensing keeps boundary points and discards interior ones, and it keeps mislabelled points for the same reason it keeps boundary ones.

  • Why does an editing pass before condensing help so much?
    Editing removes points whose own neighbours disagree with their label, which is a good proxy for mislabelled or freak rows. Condensing afterwards then sees a cleaner boundary, so it retains fewer points and does not build a prototype set around the noise. Run in the other order, condensing has already locked the noisy points in and the editing pass has less to work with.
  • The condensed subset is consistent on the training data. Why is that not enough?
    Consistency only says the subset reproduces the original labels on the original points under 1-NN. It says nothing about new queries, which can fall in regions where the removed interior points would have mattered — and nothing at all about generalisation. The only honest check is held-out accuracy on data untouched by the reduction, compared against the full stored set.
  • How do you decide whether the reduction is worth shipping?
    Quantify both sides. On one side the reduction ratio and what it buys: query latency, memory, and whether the set now fits on one machine. On the other side the held-out accuracy delta and where errors moved — usually toward boundary cases. If accuracy drops materially on a class that matters, the cheaper answer is a faster search over the full set.

Redrawing a national border from a map of towns: you only need the towns close to the frontier. The trouble is that a town wrongly coloured for the other side looks just like a frontier town, so it is the first thing you keep.

saying these in an interview costs you the question

  • Says it keeps the points nearest each class centre
  • Claims it removes noisy or mislabelled examples
  • Treats training consistency as a test-accuracy guarantee
  • Believes the resulting subset is the smallest possible
  • Assumes probability estimates survive the reduction unchanged

context