8
$\begingroup$

I am working on a recommendation engine, and I have chosen to use SciPy's cosine distance as a way of comparing items.

I have two vectors:

a = [2.7654870801855078, 0.35995355443076027, 0.016221679989074141, -0.012664358453398751, 0.0036888812311235068]

and

b = [-6.2588482809118942, -0.88952297609194686, 0.017336984676103874, -0.0054928004763216964, 0.011122959185936367]

Running the following code will produce an output of ~1.999:

from scipy.spatial import distance
print(distance.cosine(a,b))

Is there something wrong with my input values? Anyone know why I am getting a result of >1?

$\endgroup$

1 Answer 1

10
$\begingroup$

The cosine distance formula is:

enter image description here

And the formula used by the cosine function of the spatial class of scipy is:

enter image description here

So, the actual cosine similarity metric is: -0.9998.

So, it signifies complete dissimilarity.

$\endgroup$
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.