def explain(self, userid, user_items, itemid, user_weights=None, N=<NUM_LIT:10>):
<EOL>user_items = user_items.tocsr()<EOL>if user_weights is None:<EOL><INDENT>A, _ = user_linear_equation(self.item_factors, self.YtY,<EOL>user_items, userid,<EOL>self.regularization, self.factors)<EOL>user_weights = scipy.linalg.cho_factor(A)<EOL><DEDENT>seed_item = self.item_factors[itemid]<EOL>weighted_item = scipy.linalg.cho_solve(user_weights, seed_item)<EOL>total_score = <NUM_LIT:0.0><EOL>h = []<EOL>for i, (itemid, confidence) in enumerate(nonzeros(user_items, userid)):<EOL><INDENT>if confidence < <NUM_LIT:0>:<EOL><INDENT>continue<EOL><DEDENT>factor = self.item_factors[itemid]<EOL>score = weighted_item.dot(factor) * confidence<EOL>total_score += score<EOL>contribution = (score, itemid)<EOL>if i < N:<EOL><INDENT>heapq.heappush(h, contribution)<EOL><DEDENT>else:<EOL><INDENT>heapq.heappushpop(h, contribution)<EOL><DEDENT><DEDENT>items = (heapq.heappop(h) for i in range(len(h)))<EOL>top_contributions = list((i, s) for s, i in items)[::-<NUM_LIT:1>]<EOL>return total_score, top_contributions, user_weights<EOL>
Provides explanations for why the item is liked by the user.

        Parameters
        ---------
        userid : int
            The userid to explain recommendations for
        user_items : csr_matrix
            Sparse matrix containing the liked items for the user
        itemid : int
            The itemid to explain recommendations for
        user_weights : ndarray, optional
            Precomputed Cholesky decomposition of the weighted user liked items.
            Useful for speeding up repeated calls to this function, this value
            is returned
        N : int, optional
            The number of liked items to show the contribution for

        Returns
        -------
        total_score : float
            The total predicted score for this user/item pair
        top_contributions : list
            A list of the top N (itemid, score) contributions for this user/item pair
        user_weights : ndarray
            A factorized representation of the user. Passing this in to
            future 'explain' calls will lead to noticeable speedups