def recommend(self, userid, user_items,
                  N=10, filter_already_liked_items=True, filter_items=None, recalculate_user=False):
        """ returns the best N recommendations for a user given its id"""
        if userid >= user_items.shape[0]:
            raise ValueError("userid is out of bounds of the user_items matrix")

        # recalculate_user is ignored because this is not a model based algorithm
        items = N
        if filter_items:
            items += len(filter_items)

        indices, data = self.scorer.recommend(userid, user_items.indptr, user_items.indices,
                                              user_items.data, K=items,
                                              remove_own_likes=filter_already_liked_items)
        best = sorted(zip(indices, data), key=lambda x: -x[1])

        if not filter_items:
            return best

        liked = set(filter_items)
        return list(itertools.islice((rec for rec in best if rec[0] not in liked), N))
def recommend ( self , userid , user_items , N = 10 , filter_already_liked_items = True , filter_items = None , recalculate_user = False ) : if userid >= user_items . shape [ 0 ] : raise ValueError ( "userid is out of bounds of the user_items matrix" ) items = N if filter_items : items += len ( filter_items ) indices , data = self . scorer . recommend ( userid , user_items . indptr , user_items . indices , user_items . data , K = items , remove_own_likes = filter_already_liked_items ) best = sorted ( zip ( indices , data ) , key = lambda x : - x [ 1 ] ) if not filter_items : return best liked = set ( filter_items ) return list ( itertools . islice ( ( rec for rec in best if rec [ 0 ] not in liked ) , N ) )
returns the best N recommendations for a user given its id