def cal_recom_result(sim_info,user_click): ''' recom by itemcf Args: sim_info:item sim dict user_click:user click dict Return: dict,key:userid value dict,value_key itemid,value_value recom_score ''' recent_click_num=3 topk=5 recom_info={} for user in user_click: click_list=user_click[user] recom_info.setdefault(user,{}) for itemid in click_list[:recent_click_num]: if itemid not in sim_info: continue for itemsimzuhe in sim_info[itemid][:topk]: itemsimid=itemsimzuhe[0] itemsimscore=itemsimzuhe[1] return recom_info
相关分类