|
|
@@ -10,22 +10,21 @@ def run_hot_recall(order_data):
|
|
|
hot_model.calculate_all_hot_score()
|
|
|
print("热度召回已完成!")
|
|
|
|
|
|
-def run_itemcf(args):
|
|
|
+def run_itemcf(order_data, args):
|
|
|
# """运行协同过滤算法"""
|
|
|
- # if os.path.exists(args.interst_score_path) and os.path.exists(args.similarity_matrix_path):
|
|
|
- # os.remove(args.interst_score_path)
|
|
|
- # os.remove(args.similarity_matrix_path)
|
|
|
- # # n_jobs = 4
|
|
|
+ if os.path.exists(args.interst_score_path) and os.path.exists(args.similarity_matrix_path):
|
|
|
+ os.remove(args.interst_score_path)
|
|
|
+ os.remove(args.similarity_matrix_path)
|
|
|
|
|
|
- # # 计算user-score-item数据
|
|
|
- # cal_interest_scores_model = UserItemScore()
|
|
|
- # scores = cal_interest_scores_model.score(order_data)
|
|
|
- # scores.to_csv(args.interst_score_path, index=False, encoding="utf-8")
|
|
|
- # print("Interest Scores cal done!")
|
|
|
+ # 计算user-score-item数据
|
|
|
+ cal_interest_scores_model = UserItemScore()
|
|
|
+ scores = cal_interest_scores_model.score(order_data)
|
|
|
+ scores.to_csv(args.interst_score_path, index=False, encoding="utf-8")
|
|
|
+ print("Interest Scores cal done!")
|
|
|
|
|
|
- # # 计算商户共现矩阵及相似度矩阵
|
|
|
- # calculate_similarity_and_save_results(order_data, args.similarity_matrix_path)
|
|
|
- # print("Shops similarity matrix cal done!")
|
|
|
+ # 计算商户共现矩阵及相似度矩阵
|
|
|
+ calculate_similarity_and_save_results(order_data, args.similarity_matrix_path)
|
|
|
+ print("Shops similarity matrix cal done!")
|
|
|
|
|
|
# 运行协同过滤召回
|
|
|
itemcf_model = ItemCFModel()
|
|
|
@@ -77,8 +76,8 @@ def run():
|
|
|
run_hot_recall(order_data)
|
|
|
|
|
|
elif args.run_itemcf:
|
|
|
- # order_data = load_order_data_from_mysql()
|
|
|
- run_itemcf(args)
|
|
|
+ order_data = load_order_data_from_mysql()
|
|
|
+ run_itemcf(order_data, args)
|
|
|
|
|
|
elif args.run_itemcf_inference:
|
|
|
recomments = run_itemcf_inference(args.product_code)
|