gpt4 book ai didi

python - 曼哈顿距离推荐系统Python

转载 作者:太空宇宙 更新时间:2023-11-03 19:01:04 25 4
gpt4 key购买 nike

所以我已经尝试了一段时间,但就是无法让它发挥作用。如果您查看图片,您会在 x 轴和 y 轴上看到两个人,两者都是他们对电影的评分。问题是我如何计算这些人与人之间的曼哈顿距离。

enter image description here

这就是我已经拥有的...编辑我忘了说 prefs 是一个字典,以人名作为键,第二个字典作为值。第二个字典包含电影作为键,评级作为值..而 person1 和 2 只是带有名称的字符串,可以在首选项中找到

def sum_manhattan(prefs,person1,person2):
"""Calculates the Manhattan distance between two critics"""
total = 0
##assume person1 is the x axes and person 2 is the y axes
x = prefs[person1]
y = prefs[person2]

for movie in x:
if movie in y:
total = abs(x[movie]-y[movie])
return total

欢迎任何帮助:)

最佳答案

根据 Alkini 发布的链接,我认为您应该替换

total = abs(x[movie]-y[movie])

total += abs(x[movie]-y[movie])

让事情顺利进行。

您发布的代码的作用是返回上一部电影评分之间差异的绝对值,而我认为您需要添加所有电影的评分差异。

关于python - 曼哈顿距离推荐系统Python,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16062594/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com