Cosine similarity formula: cos(θ) = (A · B) / (||A|| ||B||)
Image: Tupperware Ltd., CC BY-SA 3.0, via Wikimedia Commons
Cosine similarity formula: cos(θ) = (A · B) / (||A|| ||B||)
Cosine similarity measures the cosine of the angle between two vectors, which is calculated as the dot product of the vectors divided by the product of their lengths. This metric is useful for determining the similarity between vectors without being affected by their magnitudes.
For instance, if vector A = [1, 2] and vector B = [2, 4], the dot product A · B = 1*2 + 2*4 = 10. The lengths ||A|| = √(1² + 2²) = √5 and ||B|| = √(2² + 4²) = √20. Thus, cosine similarity = 10 / (√5 * √20) = 10 / √100 = 1.
Understanding cosine similarity is crucial in fields like information retrieval and text mining, where it helps compare documents represented as vectors of word occurrences.
Remember this
Cosine similarity is a fundamental concept in vector space models used in various applications, including search engines and recommendation systems.
Text adapted from Wikipedia, licensed under CC BY-SA 4.0.
List of algorithms
Cosine similarity measures the angle between vectors, not their magnitude
Covariance matrix
Covariance formula: Cov(X, Y) = E[(X - E[X])(Y - E[Y])]
the dot product measures alignment: it equals |a||b|cos(θ)
Why do vectors sometimes "agree" with each other?
cosine similarity is preferred over dot product for normalized embeddings
Why do we need a special way to measure similarity in high-dimensional spaces?
Dot product
Dot product = sum of products of corresponding entries
Euclidean distance
Euclidean distance formula: √((x2 - x1)² + (y2 - y1)²)
Swipe through 100 ML concepts daily
Open Pocket Polymath