Commit 2a2687cd by 王金柱

创建conda环境时候,environment.yaml 添加pip的国内源文件

parent 9121e5a1
...@@ -10,3 +10,5 @@ dependencies: ...@@ -10,3 +10,5 @@ dependencies:
- pip - pip
- pip: - pip:
- -r requirements.txt - -r requirements.txt
- -i http://pypi.mirrors.ustc.edu.cn/simple/
- --trusted-host pypi.mirrors.ustc.edu.cn
...@@ -23,7 +23,7 @@ from ydl_ai_recommender.src.core.profile import encode_user_profile ...@@ -23,7 +23,7 @@ from ydl_ai_recommender.src.core.profile import encode_user_profile
from ydl_ai_recommender.src.utils import get_conf_path, get_data_path, read_user_encoder_dict, read_counselors, get_project_path from ydl_ai_recommender.src.utils import get_conf_path, get_data_path, read_user_encoder_dict, read_counselors, get_project_path
from ydl_ai_recommender.src.utils.log import create_logger from ydl_ai_recommender.src.utils.log import create_logger
logger = create_logger(__name__, 'service_xgb.log', is_rotating=True) logger = create_logger(__name__, 'recommender.log', is_rotating=True)
def cost_time(desc): def cost_time(desc):
...@@ -37,7 +37,7 @@ def cost_time(desc): ...@@ -37,7 +37,7 @@ def cost_time(desc):
return the_func_cost_time return the_func_cost_time
class Recommender(): class Recommender:
def __init__(self) -> None: def __init__(self) -> None:
self.logger = create_logger(__name__, 'recommender.log') self.logger = create_logger(__name__, 'recommender.log')
...@@ -256,6 +256,7 @@ class ItemCFRecommender(Recommender): ...@@ -256,6 +256,7 @@ class ItemCFRecommender(Recommender):
counselors = counselors[:size] counselors = counselors[:size]
return counselors return counselors
class RecommendByXgboost(Recommender): class RecommendByXgboost(Recommender):
def __init__(self, top_n=5, k=20, is_use_db=True, u2c='combination', c2c=None) -> None: def __init__(self, top_n=5, k=20, is_use_db=True, u2c='combination', c2c=None) -> None:
super().__init__() super().__init__()
...@@ -278,14 +279,12 @@ class RecommendByXgboost(Recommender): ...@@ -278,14 +279,12 @@ class RecommendByXgboost(Recommender):
self.model = xgb.XGBClassifier(objective='binary:logistic', nthread=-1, **self.params) self.model = xgb.XGBClassifier(objective='binary:logistic', nthread=-1, **self.params)
self.model.load_model(os.path.join(get_project_path(), 'model_data/xgb_model.bin')) self.model.load_model(os.path.join(get_project_path(), 'model_data/xgb_model.bin'))
@cost_time(desc='') @cost_time(desc='召回咨询师')
def recall_data(self, user_id, size=0, is_merge=True): def recall_data(self, user_id, size=0, is_merge=True):
return self.recommender.recommend(user_id, size=size, is_merge=True) return self.recommender.recommend(user_id, size=size, is_merge=True)
@cost_time(desc='模型推荐整个流程') @cost_time(desc='模型推荐整个流程')
def recommend(self, user_id, size=0, is_merge=True): def recommend(self, user_id, size=0, is_merge=True):
s_u_profile_time = time.time()
user_profile = self.get_user_profile(user_id) user_profile = self.get_user_profile(user_id)
if not user_profile: if not user_profile:
return self._recommend_top(size) return self._recommend_top(size)
...@@ -299,7 +298,7 @@ class RecommendByXgboost(Recommender): ...@@ -299,7 +298,7 @@ class RecommendByXgboost(Recommender):
pre_time = time.time() pre_time = time.time()
predit_result = self.model.predict_proba(predit_data)[:, 1] predit_result = self.model.predict_proba(predit_data)[:, 1]
logger.info('predit_time:{}ms'.format(int((time.time()-pre_time)*1000))) self.logger.info('predit_time:{}ms'.format(int((time.time()-pre_time)*1000)))
result_dict = dict(zip(doctor_ids, predit_result)) result_dict = dict(zip(doctor_ids, predit_result))
result_dict = sorted(result_dict.items(), key=lambda x:x[1], reverse=True) result_dict = sorted(result_dict.items(), key=lambda x:x[1], reverse=True)
recommend_data = [{ recommend_data = [{
...@@ -390,8 +389,6 @@ class RecommendByXgboost(Recommender): ...@@ -390,8 +389,6 @@ class RecommendByXgboost(Recommender):
encoder_result.append(value_convert_dict.get(val, 0)) encoder_result.append(value_convert_dict.get(val, 0))
if len(encoder_result)<5: if len(encoder_result)<5:
encoder_result.extend([0]*(5-len(encoder_result))) encoder_result.extend([0]*(5-len(encoder_result)))
return encoder_result return encoder_result
def get_encoder_from_dict(self, feature_name, feature_value): def get_encoder_from_dict(self, feature_name, feature_value):
...@@ -399,8 +396,6 @@ class RecommendByXgboost(Recommender): ...@@ -399,8 +396,6 @@ class RecommendByXgboost(Recommender):
if value_convert_dict is None: if value_convert_dict is None:
return 0 return 0
return value_convert_dict.get(str(feature_value), 0) return value_convert_dict.get(str(feature_value), 0)
def aa(self):
pass
if __name__ == '__main__': if __name__ == '__main__':
......
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