# Cosine similarity?

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}$$

since

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

And

$$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.

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