Cosine Similarity

S

subhabangalore

Dear Group,

I am looking for some example of implementing Cosine similarity in python. I searched for hours but could not help much. NLTK seems to have a module but did not find examples.

If anyone of the learned members may kindly help out.

Regards,
Subhabrata.
 
M

Miki Tebeka

I am looking for some example of implementing Cosine similarity in python. I searched for hours but could not help much. NLTK seems to have a module but did not find examples.
Should be easy with numpy:
import numpy as np

def cos(v1, v2):
return np.dot(v1, v2) / (np.sqrt(np.dot(v1, v1)) * np.sqrt(np.dot(v2, v2)))


HTH,
 
S

subhabangalore

T

Should be easy with numpy:

import numpy as np



def cos(v1, v2):

return np.dot(v1, v2) / (np.sqrt(np.dot(v1, v1)) * np.sqrt(np.dot(v2, v2)))





HTH,

Thanks Miki. It worked. Regards,Subhabrata.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,708
Latest member
SherleneF1

Latest Threads

Top