8

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?

Dawny33
  • 8,296
  • 12
  • 48
  • 104
redgem
  • 183
  • 1
  • 1
  • 4

1 Answers1

10

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.

Dawny33
  • 8,296
  • 12
  • 48
  • 104