tfvect = TfidfVectorizer(use_idf=True, stop_words = 'english')
wholeword = df_all['search_term']+" "+df_all['product_title']
vocab = tfvect.fit_transform(wholeword)
st = tfvect.transform(df_all['search_term'])
pt = tfvect.transform(df_all['product_title'])
I want to get the cosine similarity between each row of st and pt and store it in df_all['similarity'].
对每对行使用scipy.distance.cosine(v1,v2) http://docs.scipy.org/doc/scipy-0.14.0/reference/generation/scipy.spatial.distance.cosine.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.