def top_k_recommendations(self, sequence, k=10, exclude=None, **kwargs):
if exclude is None:
exclude = []
last_item = int(sequence[-1][0])
if last_item not in self.previous_recommendations:
self.get_all_recommendations(last_item)
all_recommendations = deepcopy(self.previous_recommendations[last_item])
for s in sequence:
all_recommendations[int(s[0])] = 0
for i in exclude:
all_recommendations[i] = 0
ranking = np.zeros(self.n_items)
for i, x in enumerate(all_recommendations.most_common(k)):
ranking[x[0]] = k-i
return np.argpartition(-ranking, range(k))[:k]
markov_model.py 文件源码
python
阅读 30
收藏 0
点赞 0
评论 0
评论列表
文章目录