Advertisement
Guest User

Untitled

a guest
Apr 25th, 2019
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.68 KB | None | 0 0
  1. import os, io
  2.  
  3. def read_item_names():
  4. """Read the u.item file from MovieLens 100-k dataset and returns a
  5. mapping to convert raw ids into movie names.
  6. """
  7.  
  8. file_name = (os.path.expanduser('~') +
  9. '/.surprise_data/ml-100k/ml-100k/u.item')
  10. rid_to_name = {}
  11. with io.open(file_name, 'r', encoding='ISO-8859-1') as f:
  12. for line in f:
  13. line = line.split('|')
  14. rid_to_name[line[0]] = line[1]
  15.  
  16. return rid_to_name
  17.  
  18. top3_recommendations = get_top3_recommendations(predictions)
  19. rid_to_name = read_item_names()
  20. for uid, user_ratings in top3_recommendations.items():
  21. print(uid, [rid_to_name[iid] for (iid, _) in user_ratings])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement