P值计算好像不太对
老师你好,感谢分享!有个小问题:
ICF中最后P值计算,是指与J最相似的K个物品,和用户U操作过的物品的交集,把他们的s求和。这个应该要遍历所有物品吧?
但是视频代码中,取用户操作过的前3个物品,再取它最相似的K个物品,似乎不太符合
我重写了下,老师你看有问题么,非常感谢!
def cal_recom_result_2(sim_info,user_click): """ recom by item collaboritive filter Args: sim_info:item sim dict user_click:user click dict Return: dict,key:userid value dict, value_key itemid,value_value recome_score """ topk = 5 recom_info = {} for user in user_click: click_list = user_click[user] recom_info.setdefault(user,{}) for itemid_i,sim_item in sim_info.items(): for itemid_j,sim_score in sim_item[:topk]: if itemid_j not in click_list: continue recom_info[user].setdefault(itemid_j,0) recom_info[user][itemid_j] += sim_score return recom_info