Cosine similarity vs Euclidean — when do you use cosine?
mediumAnswer
- Cosine similarity = x · — measures angle, ignores magnitude.
- Use when magnitude is irrelevant: TF-IDF vectors (doc length varies), sentence embeddings, user-item preferences.
- Use Euclidean when magnitude matters (physical measurements, absolute values).
- In practice: L2-normalize embeddings then use Euclidean → equivalent to cosine but works in standard k-means / FAISS indexes.
Check yourself — multiple choice
- Same thing
- Cosine: angle only (magnitude-invariant); Euclidean: absolute distance. L2-normalize then Euclidean ≡ cosine — enables k-means / FAISS
- Random
- Only for text
Cosine: angle-only; Euclidean after L2-norm ≡ cosine (usable in k-means).
#clustering#similarity
Practise Unsupervised Learning
214 interview questions in this topic.
Related questions
- How do you cluster mixed numeric + categorical data?
- Why do you scale features before k-means?
- What is Dynamic Time Warping?
- You run k-means on customer data with age, income and number of purchases. What breaks?
- How does k-means work and what are its main limitations?
- How do you choose the number of clusters k?