Description Usage Arguments Details Value References See Also
View source: R/nearest_point.R
This function computes the cosine similarity between two vectors, defined by
cos(θ) = (x . y) / (|x| |y|).
1 | cosine_similarity(x, y)
|
x |
A numeric vector |
y |
A numeric vector, the same length as |
Cosine similarity is related to Euclidean distance by
|x - y|^2 = 2(1 - cos(θ)).
So
cos(θ) = 1 - 0.5 * |x - y|^2,
assuming x
and y
have been normalised to be unit vectors.
Therefore, if we want to maximise cosine similarity, we can minimise Euclidean distance
and then make the conversion. See nearest_point()
.
Generally, a scalar between -1 and 1.
Or, if x
and y
are non-negative, a value between 0 and 1.
https://en.wikipedia.org/wiki/Cosine_similarity
nearest_cosine()
, cos()
, acos()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.