1
所以我一直在嘗試這一段時間,但只是不能得到它的工作。如果您查看圖片,您會看到x和y軸上有2個人,並且這兩個人都是他們給電影的評分。問題是我如何計算曼哈頓與人之間的距離。曼哈頓距離推薦系統Python
所以這是我已經有... 編輯 我忘了說,首選項是PERSONNAME爲重點,並與第二字典作爲值的字典。第二字典包含電影,重點和評價作爲價值..和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
任何幫助都是歡迎的。
什麼是不工作?我看到在循環中你總共= abs(...)。這是你在你的程序中做了什麼,或者是你在問題中錯誤輸入的內容? – civilu
我們是否假定prefs,person1和person2的結構與編程集體智能(圖像被解除)相同? http://answers.oreilly.com/topic/1066-how-to-find-similar-users-with-python/ – Alkini
我很抱歉..是的,這正是它是什麼,但這是我的教授給我的 我忘了說prefs是一個以personname爲關鍵字的詞典,第二個詞典是它的值。第二個字典包含電影作爲關鍵和評級作爲價值..而person1和2只是名稱的字符串,可以在prefs –