如何使用scipy.spatial.distance.cosine计算加权相似度?

3
从函数定义中可以看出:https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cosine.html scipy.spatial.distance.cosine(u, v, w=None)
但我的代码出现了一些错误:
from scipy import spatial
d1 = [3,5,5,3,3,2]
d2 = [1,1,3,1,3,2]
weight_of_importance = [0.1,0.1,0.2,0.2,0.1,0.3]

result = spatial.distance.cosine(d1, d2, weight_of_importance)
print(result)

类型错误:cosine()需要2个位置参数,但提供了3个

当我只输入2个参数时它可以工作。 但是这些特征具有不同的重要性权重。 如何在d1和d2的加权重要性下计算相似度?


它在scipy 1.1.0中正常工作。你的版本是什么? - MaxU - stand with Ukraine
它在scipy 1.0.1中有效。 - Mr. T
1个回答

2

谢谢。我真的好迷糊。 - DataHolic

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接