Why Use Cosine Similarity Over Euclidean Distance? Insights & Limits
This article explains the concept of cosine distance, compares it with Euclidean distance, discusses when cosine similarity is preferable, and shows why cosine distance does not satisfy all metric axioms, providing examples and interview‑style analysis.
This is the fifth article in the Hulu machine‑learning interview series, focusing on cosine distance.
Cosine Distance Overview
In machine learning, features are often represented as vectors. Cosine similarity measures the angle between two vectors, ranging from -1 to 1, with identical vectors having a similarity of 1. Cosine distance is defined as 1 minus cosine similarity, yielding values in the range [0, 2]; identical vectors have a distance of 0.
Question 1: When to Prefer Cosine Similarity?
Cosine similarity considers only the angular relationship between vectors and ignores their magnitudes, making it suitable for comparing texts or other high‑dimensional data where vector lengths differ but content is similar. Euclidean distance can be large for such cases because it is magnitude‑sensitive. In high‑dimensional spaces (e.g., word2vec embeddings), cosine similarity remains stable (1 for identical direction, 0 for orthogonal, -1 for opposite), whereas Euclidean distance varies with dimensionality. When vectors are normalized to unit length, Euclidean distance and cosine similarity become monotonically related, so selecting the nearest neighbor by either metric yields the same result.
Question 2: Is Cosine Distance a Proper Metric?
Cosine distance does not satisfy all three metric axioms. It fulfills positive definiteness and symmetry but violates the triangle inequality. The article presents a counterexample with points A = (1,0), B = (1,1), C = (0,1) to demonstrate the failure of the triangle inequality.
The article also notes that other commonly used “distances” such as KL divergence are not true metrics because they lack symmetry and the triangle inequality.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Hulu Beijing
Follow Hulu's official WeChat account for the latest company updates and recruitment information.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
