基于内容的电影推荐:为用户产生TOP-N推荐结果
user_profile = create_user_profile()
watch_record = pd.read_csv("datasets/ml-latest-small/ratings.csv", usecols=range(2),dtype={
"userId": np.int32, "movieId": np.int32})
watch_record = watch_record.groupby("userId").agg(list)
for uid, interest_words in user_profile.items():
result_table = {
}
for interest_word, interest_weight in interest_words:
related_movies = inverted_table[interest_word]
for mid, related_weight in related_movies:
_ = result_table.get(mid, [])
_.append(interest_weight)
result_table.setdefault(mid, _)
rs_result = map(lambda x: (x[0], sum(x[1])), result_table.items())
rs_result = sorted(rs_result, key=lambda x:x[1], reverse=True)[:100]
print(uid)
pprint(rs_result)
break