We were doing project work for plagiarism checking. For this purpose, we have taken a term frequency vector of two documents and measured the similarity using a cosine similarity measure. The value of cosine similarity is limited between 0 and 1. We know that the value of cosine similarity will be 1 if two documents exactly match with one another. In this case, we can say 100% match. Moreover, the value will be 0 for no match i.e. 0 % match. Furthermore, if the value is 0.65, then how do we find the percentage from this score? The definition and formula of cosine similarity are shown in the following figure. Fig. Cosine Similarity Calculation

  • $\begingroup$ Don't use an image of text or mathematics. This makes your question impossible to search and inaccessible to the visually impaired; we don't like that. Please transcribe text and mathematics. You can use LaTeX. Also, we require you to provide proper attribution for the source of that material. $\endgroup$
    – D.W.
    Nov 9, 2021 at 4:37

1 Answer 1


Suppose that your two vectors $x,y$ belong to $\{\pm1\}^n$. The formula of cosine similarity in this case gives the cosine similarity as $$ \frac{1}{n} \sum_{i=1}^n x_i y_i = \frac{\#\{i : x_i = y_i\} - \#\{i : x_i \neq y_i\}}{n} = 1 - 2\Pr_i[x_i \neq y_i] = 2\Pr_i[x_i=y_i] - 1. $$ As can be seen, the range of cosine similarity is actually $[-1,1]$.

Sometimes other proxies of cosine similarity are used. For example, cosine distance is one minus cosine similarity; this ranges over $[0,2]$. Similarly, "half cosine distance" is half the cosine distance, which ranges over $[0,1]$. In the case above, half cosine distance is exactly $\Pr_i[x_i \neq y_i]$.

Starting with the actual cosine similarity $S$, you can extract $\Pr_i[x_i = y_i]$ as $\frac{1+S}{2}$. In the case of two vectors $x,y \in \{\pm 1\}^n$, this is the percentage of indices in which $x_i$ equals $y_i$. For general vectors $x,y$, the quantity $\frac{1+S}{2}$ no longer has this interpretation. It is just a distance measure.

  • $\begingroup$ Thanks for your quick and nice explanation. But I am going the use the above formula shown in the edited question. Can you please reply in this regard? $\endgroup$ Nov 8, 2021 at 16:20
  • $\begingroup$ That’s also the formula I use. $\endgroup$ Nov 8, 2021 at 19:10

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.