Euclidean vs. cosine similarity

I have a text dataset which I vectorize using a tfidf technique and now in order to make a cluster analysis I am measuring distances between these vector representations. I have found that a common technique is to measure distance using cosine similarity, and when I ask why euclidean distance is not used, the common answer is that cosine similarity works better when vectors have different magnitude.

Since my text vectorized representation is normalized I wonder which is the advantage of using cosine similarity over euclidean distance in order to cluster my data?

1 Answer

On L2 normalized data it is an easy and good exercise to prove that they are equivalent.

So you should try to solve the math yourself.

Hint: use squared Euclidean.

Note that it is common with tfidf to not have normalized data because of various technical reasons, e.g., when using inverted indexes in text search. Furthermore, cosine is faster on very sparse data.

• That's very useful. I will prove the equivalence. Commented Apr 11, 2018 at 19:46
• @FedericoCaccia You could write the prove as an answer here. Commented Apr 15, 2018 at 20:36
• The proof is so straightforward that you are better served doing it yourself than just reading it here. That is why I didn't include it. Commented Apr 15, 2018 at 23:31