Skip to content
Search

Cosine similarity

lastmod 2025-01-17created 2025-01-171 edits

Cosine similarity (― 類似度) is the degree of similarity between two vectors in an inner product space, measured using the cosine of the angle between them. The cosine of 0° is 1, and the cosine of every other angle is less than 1. So this value is used to judge the similarity of direction, not magnitude, of vectors: it is 1 when the two vectors point in exactly the same direction, 0 when they form a 90° angle, and -1 when they point in completely opposite directions at 180°. The magnitude of the vectors has no effect on the value. Cosine similarity is used especially in number spaces where the result falls in the range [0,1].

Cosine similarity can be applied to any number of dimensions, so it is often used to measure similarity in multidimensional positive spaces. For example, in information retrieval and text mining, each word forms its own dimension, and a document has a vector value expressed by the number of times each word appears in it. In such a multidimensional space, cosine similarity is a very useful way to measure the similarity of two documents.

Cosine similarity is also used in data mining as a way to measure cohesion within clusters.

Don't use cosine similarity carelessly

Data scientists turn everything into vectors. This is the language of AI. But applying cosine similarity blindly can lead you in the wrong direction.

See also

Favorite site

author Zer0 sitemap