def top_k_recommendations(self, sequence, user_id=None, k=10, exclude=None):
''' Recieves a sequence of (id, rating), and produces k recommendations (as a list of ids)
'''
if exclude is None:
exclude = []
last_item = sequence[-1][0]
output = self.bias + np.dot(self.V[user_id, :], self.H.T)
# Put low similarity to viewed items to exclude them from recommendations
output[[i[0] for i in sequence]] = -np.inf
output[exclude] = -np.inf
# find top k according to output
return list(np.argpartition(-output, range(k))[:k])
评论列表
文章目录