2.5.3推薦システムアルゴリズム---コンテンツに基づく映画推薦:ユーザーにTOP-N推薦結果を生成する
5788 ワード
# ......
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 = {} # id:[0.2,0.5,0.7]
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) #
# _.append(related_weight) #
# _.append(interest_weight*related_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
# ==> ==>
# ===> ( ) ===> ==> 100%
# : 1 、3 、7