I'm new to Data Science. I'm trying to understand cosine similarity and it seems like the equation is about finding the distance between two vectors. From what I've Googled, a vector needs to have magnitude and direction. But in CS, it seems like it's a 1-dimensional array. Is vector in CS the same as vector in Physics? If so, what is the direction of a vector. And if a vector is like this [1, 0, 1, 0]
what is the magnitude of this vector?
-
$\begingroup$ This explanation may help en.wikipedia.org/wiki/Vector_space_model $\endgroup$– paparazzoCommented Nov 4, 2015 at 10:28
2 Answers
As you ask specifically for the Cosine Similarity technique, it has magnitude and direction, and similar to a vector which is used in Physics, as Cosine Similarity deals with vectors in an inner product space.
So, the magnitude of vectors is exactly the same as the formula in Physics (summating over the squares of the vector elements.)
Yes, they are the same.
The array [1, 0, 1, 0]
represents a vector in $4$ dimensional euclidean space ($\mathbb{R}^4$) with tails at [0, 0 , 0 ,0]
and head at [1, 0, 1, 0]
. So your vector is "pointing" in the direction of your given set of coordinates.
This might be easier to visualize in $2$ dimensions: for example, the array [1,0]
corresponds to the unit vector along the $x$-axis centered at the origin.