关于余弦相似度 [英] about cosine similarity
问题描述
我发现文档之间的余弦相似性..我是这样做的
I am finding cosine similarity between documents.. I did it like this
D1=(8,0,0,1) 其中 8,0,0,1 是术语 t1, t2, t3 , t4 的 tf-idf 分数
D1=(8,0,0,1) where 8,0,0,1 are the tf-idf scores of the terms t1, t2, t3 , t4
D2=(7,0,0,1)
D2=(7,0,0,1)
cos(theta) = (56 + 0 + 0 + 1)/sqrt(64 + 49) sqrt(1 +1)
cos(theta) = (56 + 0 + 0 + 1) / sqrt(64 + 49) sqrt(1 +1 )
结果是
cos(theta)= 5
cos(theta)= 5
现在我根据这个值评估什么...我不明白 cos(theta)=5 表示它们之间的相似性...我做对了吗?
Now what do I evaluate from this value... I don't get it what does cos(theta)=5 signify about the similarity between them... Am I doing things right?
推荐答案
分母有误.
余弦相似度定义为
D1 · D2
sim = ———————————
|D1| |D2|
这里
D1 · D2 = (7*8 + 0*0 + 0*0 + 1*1) = 57
______________________ __
|D2| = √ 7^2 + 0^2 + 0^2 + 1^2 = √50
______________________ __
|D1| = √ 8^2 + 0^2 + 0^2 + 1^2 = √65
所以相似度应该是 (57/√(50 * 65)) = 0.999846142,而不是 5.
So the similarity should be (57 / √(50 * 65)) = 0.999846142, not 5.
这篇关于关于余弦相似度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!