Skip to content

Commit

Permalink
build_anti_testset() optimization (#106)
Browse files Browse the repository at this point in the history
Move user_items list out of the iteration.
  • Loading branch information
nju-luke authored and NicolasHug committed Nov 14, 2017
1 parent e8a173c commit 77d728b
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions surprise/dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,12 +694,10 @@ def build_anti_testset(self, fill=None):

anti_testset = []
for u in self.all_users():
for i in self.all_items():
user_items = [j for (j, _) in self.ur[u]]
if i not in user_items:
r_ui = (self.to_raw_uid(u), self.to_raw_iid(i),
fill)
anti_testset.append(r_ui)
user_items = set([j for (j, _) in self.ur[u]])
anti_testset += [(self.to_raw_uid(u), self.to_raw_iid(i), fill) for
i in self.all_items() if
i not in user_items]
return anti_testset

def all_users(self):
Expand Down

0 comments on commit 77d728b

Please sign in to comment.