Cosine similarity magnitude vector

23 Views Asked by At

there is one thing I'm not sure about regarding cosine similarity. Does the magnitude of the vector matter? I think the answer is yes, especially if you look at the picture below where the word count is an important factor. However, when we take the angle from the beginning, the magnitude of the vector is not relevant (because the direction doesn't change), but when we take the angle at a later point/position (as the maker of this video did), then the magnitude is a relevant factor. However, it looks to me like he took the angle (17) at a pretty arbitrary point...? I hope my question is clear.

source: https://www.youtube.com/watch?v=m_CooIRM3UI

Cosine similarity of word counts

1

There are 1 best solutions below

0
On BEST ANSWER

No, it doesn't matter. Only the directions of the vectors matter. The angle between two vectors is the angle between the two lines these vectors determine. It doesn't matter where on the lines you measure it, the angle is the same.

When you compute the cosine similarity, you really normalize the vectors anyway. Recall the formula used was

$$\textrm{Cosine similarity} = \frac{A\cdot B}{\lVert A\rVert \lVert B\rVert}$$

But that's the same as $$\frac{A}{\lVert A\rVert}\cdot \frac{B}{\lVert B\rVert}$$

which is the dot product of the vectors reduced to unit length (normalized) keeping their original directions (positive scalars don't affect the directions of vectors).

Addendum: It is also mentioned that $A\cdot B = \lVert A \rVert \lVert B\rVert \cos \theta$, where $\theta$ is the (acute) angle between $A$ and $B$. Then you get that

$$\require{cancel}\textrm{Cosine similarity} = \frac{A\cdot B}{\lVert A\rVert \lVert B\rVert} = \frac{\overbrace{\cancel{\lVert A \rVert \lVert B\rVert} \cos \theta}^{A\cdot B}}{\cancel{\lVert A \rVert \lVert B\rVert}} = \cos\theta$$