List of algorithms

Cosine similarity measures the angle between vectors, not their magnitude

Image: Loïc Le Meur, CC BY 2.0, via Wikimedia Commons

List of algorithms

Cosine similarity measures the angle between vectors, not their magnitude

Cosine similarity is a metric used to measure the similarity between two vectors by comparing the direction of the vectors, not their magnitude. This is particularly useful in high-dimensional spaces where the magnitude of vectors can be very large and less informative.

Example

Consider two vectors A = [1, 2, 3] and B = [2, 4, 6]. The cosine similarity between A and B is calculated as the dot product of A and B divided by the product of their magnitudes. In this case, the dot product is 1*2 + 2*4 + 3*6 = 28, and the magnitudes are sqrt(1^2 + 2^2 + 3^2) = sqrt(14) and sqrt(2^2 + 4^2 + 6^2) = sqrt(56). The cosine similarity is 28 / (sqrt(14) * sqrt(56)) = 0.5.

Cosine similarity is important because it focuses on the direction of vectors, making it useful for comparing the similarity of high-dimensional data, such as text embeddings or image features, where the magnitude of vectors can vary significantly.

Related concepts

One email a day: 5 concepts + the 5 stories that matter →

Swipe through 100 ML concepts daily

Open TickerNews