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 1


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.

  • $\begingroup$ That's very useful. I will prove the equivalence. $\endgroup$ Apr 11, 2018 at 19:46
  • $\begingroup$ @FedericoCaccia You could write the prove as an answer here. $\endgroup$ Apr 15, 2018 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$ Apr 15, 2018 at 23:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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