![]() |
VOOZH | about |
In this article, we are going to see how to calculate Cosine Similarity in the R Programming language.
We can define cosine similarity as the measure of the similarity between two vectors of an inner product space. The formula to calculate the cosine similarity between two vectors is:
where
We can calculate this by using the cosine() function, Thus the function is available in the module called lsa. so we have to load that module first.
Syntax: cosine(X,Y)
where
- X is the first vector
- Y is the second vector
Output:
[,1] [1,] 0.5468596
Output:
vector1 vector2 vector3 vector1 1.0000000 0.5468596 0.5468596 vector2 0.5468596 1.0000000 1.0000000 vector3 0.5468596 1.0000000 1.0000000
Note: