Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os, io
- def read_item_names():
- """Read the u.item file from MovieLens 100-k dataset and returns a
- mapping to convert raw ids into movie names.
- """
- file_name = (os.path.expanduser('~') +
- '/.surprise_data/ml-100k/ml-100k/u.item')
- rid_to_name = {}
- with io.open(file_name, 'r', encoding='ISO-8859-1') as f:
- for line in f:
- line = line.split('|')
- rid_to_name[line[0]] = line[1]
- return rid_to_name
- top3_recommendations = get_top3_recommendations(predictions)
- rid_to_name = read_item_names()
- for uid, user_ratings in top3_recommendations.items():
- print(uid, [rid_to_name[iid] for (iid, _) in user_ratings])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement