Skip to content

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also .

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also .
...
  • 2 commits
  • 1 file changed
  • 0 commit comments
  • 1 contributor
Showing with 45 additions and 0 deletions.
  1. +45 −0 recommend.py
View
45 recommend.py
@@ -0,0 +1,45 @@
+
+class Recommend():
+ def build_dict(self, users_book_list):
+ """
+ Expecting [{"name":"tom", "books":["bok1", "bok2"]},{"name":"eva", "books":["bok1"] } ]
+
+ """
+ d = {}
+ i = 0
+ for user in users_book_list:
+ for book in user["books"]:
+ if book not in d.values():
+ d[i] = book
+ i += 1
+ matrix = []
+
+ for i in xrange(len(users_book_list)):
+ row = []
+ for j in xrange(len(d)):
+ if d[j] in users_book_list[i]["books"]:
+ row.append(1)
+ else:
+ row.append(0)
+ matrix.append(row)
+
+ self.matrix = matrix
+ self.book_dictionary = d
+ def build_user(self, user_book_list):
+ """
+ Expecting list of books by user
+ """
+ user = []
+ for i in xrange(len(self.book_dictionary)):
+ if self.book_dictionary[i] in user_book_list:
+ user.append(1)
+ else:
+ user.append(0)
+ self.user = user
+ print user
+
+if __name__ == "__main__":
+ r = Recommend()
+ r.build_dict([{"name":"tom", "books":["bok1", "bok2"]},{"name":"eva", "books":["bok1"] } ])
+ r.build_user(["bok1", "bok2"])
+

No commit comments for this range

Something went wrong with that request. Please try again.