A helpdesk routes tickets with a KNN classifier using Euclidean distance on TF-IDF vectors built with norm=None (no length normalisation). Tickets range from 15 to 3,000 words. Short tickets end up with short neighbours whatever their topic, and long tickets seem far from everything. Which change fixes this?
Show the answer and explanation
Correct answer: C, Use cosine distance, or L2-normalise the vectors so Euclidean ranks neighbours the same way; both compare term proportions, so short and long tickets on one topic end up close.
Explanation KNN
Without normalisation, a document's vector grows with its length: a 3,000-word ticket has much larger term weights than a 15-word one. Euclidean distance then mostly measures magnitude: two short tickets on different topics are close because both sit near the origin, and long tickets are far from everything.
Cosine distance, 1 − a·b / (‖a‖‖b‖), depends only on the direction of the vectors, i.e. the relative proportions of the IDF-weighted terms, so a short and a long ticket about the same problem end up close. For L2-normalised vectors ‖a − b‖² = 2 − 2·cos(a, b), so Euclidean distance after normalisation ranks neighbours exactly as cosine does. (scikit-learn's TfidfVectorizer uses norm="l2" by default for this reason.)
Manhattan versus Euclidean is a different trade-off: Euclidean squares each coordinate difference, so one large difference dominates; Manhattan grows linearly and is less dominated by it.
| Difference vector | Manhattan (L1) | Euclidean (L2) |
|---|---|---|
| (4, 0, 0, 0): one large gap | 4 | 4 |
| (1, 1, 1, 1): four small gaps | 4 | 2 |
But both still scale with document length, so switching to L1 does not fix the problem.
Why the other fixes fail: standardising columns rescales each term across documents but leaves each document's overall length effect in place, and it destroys sparsity. A larger k changes how many neighbours vote, not which documents count as near.
Interview tip: the same rule applies to embeddings: most sentence-embedding models are trained for cosine similarity, so normalise them and a dot product equals cosine.