Commit 3b497d9f by 柴鹏飞

接口默认返回100条数据

parent a7c2622d
...@@ -46,7 +46,7 @@ def load_test_data(): ...@@ -46,7 +46,7 @@ def load_test_data():
def evaluation(result_detail): def evaluation(result_detail):
top_n_list = [1, 3, 5, 10] top_n_list = [1, 3, 5, 10, 20, 50, 100]
metrics = { metrics = {
'all_test_cnt': 0, 'all_test_cnt': 0,
'all_recall_cnt': 0, 'all_recall_cnt': 0,
...@@ -69,7 +69,7 @@ def evaluation(result_detail): ...@@ -69,7 +69,7 @@ def evaluation(result_detail):
for top_n, counselor in enumerate(rd['recall_counselors']): for top_n, counselor in enumerate(rd['recall_counselors']):
if counselor['counselor'] == rd['supplier_id']: if counselor['counselor'] == rd['supplier_id']:
from_info = counselor['from'].split(' ') from_info = counselor['from'].split(' ')
if from_info[0] == 'top_50': if from_info[0] == 'top_100':
metrics['default_recall_cnt'] += 1 metrics['default_recall_cnt'] += 1
else: else:
from_id = from_info[1] from_id = from_info[1]
...@@ -201,7 +201,7 @@ if __name__ == '__main__': ...@@ -201,7 +201,7 @@ if __name__ == '__main__':
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument('--mode', default=0, type=int, help='模式:0-推荐的咨询师列表去重(默认,与实际线上一样);1-推荐的咨询师列表没有去重') parser.add_argument('--mode', default=0, type=int, help='模式:0-推荐的咨询师列表去重(默认,与实际线上一样);1-推荐的咨询师列表没有去重')
parser.add_argument('--k', default=10, type=int, help='召回相似用户的数量') parser.add_argument('--k', default=20, type=int, help='召回相似用户的数量')
parser.add_argument('--top_n', default=5, type=int, help='每个相似用户召回的咨询师数量') parser.add_argument('--top_n', default=5, type=int, help='每个相似用户召回的咨询师数量')
parser.add_argument('--max_test', default=0, type=int, help='最多测试数据量') parser.add_argument('--max_test', default=0, type=int, help='最多测试数据量')
......
...@@ -63,7 +63,7 @@ class OrderDataManager(): ...@@ -63,7 +63,7 @@ class OrderDataManager():
""" """
构建索引 构建索引
用户-咨询师 索引 用户-咨询师 索引
top50 咨询师列表 用于冷启动 top100 咨询师列表 用于冷启动
""" """
self.logger.info('') self.logger.info('')
self.logger.info('开始构建 用户-咨询师 索引') self.logger.info('开始构建 用户-咨询师 索引')
...@@ -100,14 +100,14 @@ class OrderDataManager(): ...@@ -100,14 +100,14 @@ class OrderDataManager():
# 订单最多的咨询师 # 订单最多的咨询师
supplier_cnter = Counter(df['supplier_id']) supplier_cnter = Counter(df['supplier_id'])
top50_supplier = [] top100_supplier = []
for key, _ in supplier_cnter.most_common(50): for key, _ in supplier_cnter.most_common(100):
top50_supplier.append(str(key)) top100_supplier.append(str(key))
self.logger.info('top50 订单量咨询师统计完成') self.logger.info('top100 订单量咨询师统计完成')
with open(os.path.join(self.local_file_dir, 'top50_supplier.txt'), 'w', encoding='utf-8') as f: with open(os.path.join(self.local_file_dir, 'top100_supplier.txt'), 'w', encoding='utf-8') as f:
f.write('\n'.join(top50_supplier)) f.write('\n'.join(top100_supplier))
self.logger.info('top50 订单量咨询师列表已保存') self.logger.info('top100 订单量咨询师列表已保存')
if __name__ == '__main__': if __name__ == '__main__':
......
...@@ -24,7 +24,7 @@ class Recommender(): ...@@ -24,7 +24,7 @@ class Recommender():
class UserCFRecommender(Recommender): class UserCFRecommender(Recommender):
def __init__(self, top_n=5, k=10, is_use_db=True) -> None: def __init__(self, top_n=5, k=20, is_use_db=True) -> None:
super().__init__() super().__init__()
# 召回 top_n 个相似用户 # 召回 top_n 个相似用户
self.top_n = top_n self.top_n = top_n
...@@ -57,7 +57,7 @@ class UserCFRecommender(Recommender): ...@@ -57,7 +57,7 @@ class UserCFRecommender(Recommender):
with open(os.path.join(self.local_file_dir, 'user_doctor_index.json'), encoding='utf-8') as f: with open(os.path.join(self.local_file_dir, 'user_doctor_index.json'), encoding='utf-8') as f:
order_user_counselor_index = json.load(f) order_user_counselor_index = json.load(f)
with open(os.path.join(self.local_file_dir, 'top50_supplier.txt'), 'r', encoding='utf-8') as f: with open(os.path.join(self.local_file_dir, 'top100_supplier.txt'), 'r', encoding='utf-8') as f:
default_counselor = [line.strip() for line in f] default_counselor = [line.strip() for line in f]
self.order_user_embedding = order_user_embedding self.order_user_embedding = order_user_embedding
...@@ -66,7 +66,7 @@ class UserCFRecommender(Recommender): ...@@ -66,7 +66,7 @@ class UserCFRecommender(Recommender):
self.default_counselor = [{ self.default_counselor = [{
'counselor': str(user), 'counselor': str(user),
'score': 1 - 0.01 * index, 'score': 1 - 0.01 * index,
'from': 'top_50', 'from': 'top_100',
} for index, user in enumerate(default_counselor)] } for index, user in enumerate(default_counselor)]
self.index = faiss.IndexFlatL2(len(self.order_user_embedding[0])) self.index = faiss.IndexFlatL2(len(self.order_user_embedding[0]))
...@@ -91,7 +91,7 @@ class UserCFRecommender(Recommender): ...@@ -91,7 +91,7 @@ class UserCFRecommender(Recommender):
return self.manager.profile_to_embedding(user_profile) return self.manager.profile_to_embedding(user_profile)
def _recommend_top(self, size=50): def _recommend_top(self, size=100):
return self.default_counselor[:size] return self.default_counselor[:size]
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment