Skip to content

Commit 2087530

Browse files
committed
tabs to spaces
1 parent 9b5fe32 commit 2087530

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

ratings.py

Lines changed: 24 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,34 @@ def get_ratings_array(self):
2828
self.myratings[self.persons.index(person),self.papers.index(paper)] = self._data[person][paper]
2929

3030
def compare_ratings(person1, person2):
31-
# only check non-zero ratings
32-
indices = np.where(self.myratings[person1] != 0) or np.where(self.myratings[person2] != 0)
33-
if len(indices) == 0: return len(self.papers)*25+1 #5 is max difference;no basis to compare
34-
cmp1 = self.myratings[person1][indices]
35-
cmp2 = self.myratings[person2][indices]
36-
return np.linalg.norm(self.myratings[cmp1] - self.myratings[cmp2])
31+
# only check non-zero ratings
32+
indices = np.where(self.myratings[person1] != 0) or np.where(self.myratings[person2] != 0)
33+
if len(indices) == 0: return len(self.papers)*25+1 #5 is max difference;no basis to compare
34+
cmp1 = self.myratings[person1][indices]
35+
cmp2 = self.myratings[person2][indices]
36+
return np.linalg.norm(self.myratings[cmp1] - self.myratings[cmp2])
3737

3838
def recommendations(self):
3939
allrecommendations = {}
4040
for person in self.persons:
41-
minimum = len(self.papers)*25+1
42-
for otherperson in self.persons:
43-
if otherperson == person: break;
44-
tmp = compare_ratings(person, otherperson)
45-
if tmp < minimum:
46-
closest = otherperson
47-
minimum = tmp
48-
notread = np.where(np.array(self.myratings[self.persons.index(otherperson)] == 0))
49-
print self.myratings
50-
print self.persons.index(otherperson)
51-
print notread
52-
maxindex = np.where(self.myratings[self.persons.index(otherperson)][notread] == self.myratings[self.persons.index(otherperson)][notread].max())
53-
allrecommendations[person] = self._data[otherperson][maxindex]
41+
minimum = len(self.papers)*25+1
42+
notread = np.array([])
43+
for otherperson in self.persons:
44+
if otherperson == person: break;
45+
tmp = self.compare_ratings(person, otherperson)
46+
if tmp < minimum:
47+
closest = otherperson
48+
minimum = tmp
49+
notread = np.where(np.array(self.myratings[self.persons.index(otherperson)] == 0))[0]
50+
print self.myratings
51+
print self.persons.index(otherperson)
52+
print notread
53+
print len(notread)
54+
if len(notread) == 0:
55+
allrecommendations[person] = "No recommendation"
56+
else:
57+
maxindex = np.where(self.myratings[self.persons.index(otherperson)][notread] == self.myratings[self.persons.index(otherperson)][notread].max())
58+
allrecommendations[person] = self._data[otherperson][maxindex]
5459
return allrecommendations
5560

5661
# Alternative distances:

0 commit comments

Comments
 (0)