from math import sqrt
def sim_distance(prefs,person1,person2):
si={}
for item in prefs[person1]:
if item in prefs[person2]:
si[item]=1
if len(si)==0: return 0
sum_of_squares=sum([ pow ( prefs[person1] [item] - prefs[person2][item],2)
for item in prefs[person1] if item in prefs[person2]])
return 1/(1+sqrt(sum_of_squares))
reload(recommendations)
recommendations.sim_distance(critics,'Lisa Rose','Gene Seymour')
这是错误
Traceback (most recent call last):
File "<pyshell#2>", line 1, in <module>
recommendations.sim_distance(critics,'Lisa Rose','Gene Seymour')
NameError: name 'critics' is not defined
评论家是一个自定义数组