From the function definition: https://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.distance.cosine.html
scipy.spatial.distance.cosine(u, v, w=None)
but my codes got some errors:
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)
TypeError: cosine() takes 2 positional arguments but 3 were given
It works when I only input 2 parameters. But those features got different weighting of importance. How could I calculate the similarity with weighted importance for d1 and d2?
答案 0 :(得分:0)
似乎已在SciPy v1.0.0中添加了此参数。
the previous version 0.19.1中没有该参数
摘录自SciPy v1.0.0 release notes:
scipy.spatial
的改进许多距离指标 scipy.spatial.distance 获得了对体重的支持。