Let's say I have two vectors of $1$ and $-1$, and I want to know how similar these two vectors are. Is the use of the cosine similarity coefficient, justifed in this case?


Let $x, y\in\{-1,+1\}^k$. Then their cosine similarity is

$$ \cos\theta =\frac{x\cdot y}{\|x\|_2\|y\|_2}=\frac{x\cdot y}{k} $$


$$ \|x\|_2=\|y\|_2=\sqrt{k}. $$


$$ x\cdot y = \#\{i\,|\,x_i=y_i\}-\#\{i\,|\,x_i\neq y_i\}$$

simply counts the number of concordant minus the number of discordant pairs. So your cosine similarity is simply this number scaled by $k$ to $[-1,+1]$.

I'd say this kind of similarity makes perfect sense.

  • 2
    $\begingroup$ +1, especially for the subtle distinction between "justified" (as asked in the question) and "makes sense" (as answered). $\endgroup$
    – whuber
    May 30 '17 at 13:44

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.