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?


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.

| improve this answer | |
  • $\begingroup$ That's very useful. I will prove the equivalence. $\endgroup$ – Federico Caccia Apr 11 '18 at 19:46
  • $\begingroup$ @FedericoCaccia You could write the prove as an answer here. $\endgroup$ – Martin Thoma Apr 15 '18 at 20:36
  • $\begingroup$ 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. $\endgroup$ – Has QUIT--Anony-Mousse Apr 15 '18 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.