Someone please explain cosine similarity equation to me?

162 Views Asked by At

I'm trying to understand the cosine similarity in a simple and graphical way, very much similar to this question here but I do not understand how the person got to their answer.

1

There are 1 best solutions below

2
On BEST ANSWER

The vectors are $(x_1 \ x_2 \ x_3 \ x_4 \ x_5 \ x_6 \ x_7 \ x_8)^T=(2 \ 0 \ 1 \ 1 \ 0 \ \ 2 \ 1 \ 1)^T$ and $(y_1 \ y_2 \ y_3 \ y_4 \ y_5 \ y_6 \ y_7 \ y_8)^T=( \ 2 \ 1 \ 1 \ 0 \ 1 \ 1 \ 1 \ 1)^T$

The cosine of angle ($\alpha$) between the two vectors is $cos(\alpha)=\large{\frac{\sum_{i=1}^8 x_i\cdot y_i}{\sqrt{\sum_{i=1}^8 x_i^2}\cdot \sqrt{\sum_{i=1}^8 y_i^2}}}=\frac{2\cdot 2+0 \cdot 1+ 1\cdot 1+ 1\cdot 0 + 0 \cdot 1+ 2\cdot 1+ 1\cdot 1+ 1\cdot 1}{\sqrt{2^2+0^2+1^2+1^2+0^2+2^2+1^2+1^2}\cdot \sqrt{2^2+1^2+1^2+0^2+1^2+1^2+1^2+1^2}}$

$=\frac{4+1+2+1+1}{\sqrt{4+1+1+4+1+1}\cdot \sqrt{4+1+1+1+1+1+1}}=\frac{9}{\sqrt{12}\cdot \sqrt{10}}=0.8216$

Thus the equation is $\cos(\alpha)=0.8216$

$\alpha=arcos(0.8216)=34.76°$