余弦相似性的原理及应用
请点击下面链接查看转载文章:
TF-IDF与余弦相似性的应用
余弦相似度的python实现:
def count_cos_similarity(vec_1, vec_2):
if len(vec_1) != len(vec_2):
return 0
s = sum(vec_1[i] * vec_2[i] for i in range(len(vec_2)))
den1 = math.sqrt(sum([pow(number, 2) for number in vec_1]))
den2 = math.sqrt(sum([pow(number, 2) for number in vec_2]))
return s / (den1 * den2)
参考:https://blog.csdn.net/m0_37693335/article/details/78617138