def f1AtK(positiveArray, orderedItems, k, verbose=False): """ Return the F1@k measure for each row of the predicted matrix UV.T using real values in positiveArray. positiveArray is a tuple (indPtr, colInds) :param orderedItems: The ordered items for each user (users are rows, items are cols) :param verbose: If true return recall and first k recommendation for each row, otherwise just precisions """ if type(positiveArray) != tuple: positiveArray = SparseUtils.getOmegaListPtr(positiveArray) orderedItems = orderedItems[:, 0:k] indPtr, colInds = positiveArray precisions = MCEvaluatorCython.precisionAtk(indPtr, colInds, orderedItems) recalls = MCEvaluatorCython.recallAtk(indPtr, colInds, orderedItems) denominator = precisions+recalls denominator += denominator == 0 f1s = 2*precisions*recalls/denominator if verbose: return f1s, orderedItems else: return f1s.mean()
def f1AtK(positiveArray, orderedItems, k, verbose=False): """ Return the F1@k measure for each row of the predicted matrix UV.T using real values in positiveArray. positiveArray is a tuple (indPtr, colInds) :param orderedItems: The ordered items for each user (users are rows, items are cols) :param verbose: If true return recall and first k recommendation for each row, otherwise just precisions """ if type(positiveArray) != tuple: positiveArray = SparseUtils.getOmegaListPtr(positiveArray) orderedItems = orderedItems[:, 0:k] indPtr, colInds = positiveArray precisions = MCEvaluatorCython.precisionAtk(indPtr, colInds, orderedItems) recalls = MCEvaluatorCython.recallAtk(indPtr, colInds, orderedItems) denominator = precisions + recalls denominator += denominator == 0 f1s = 2 * precisions * recalls / denominator if verbose: return f1s, orderedItems else: return f1s.mean()
def precisionAtK(positiveArray, orderedItems, k, verbose=False): """ Compute the average precision@k score for each row of the predicted matrix UV.T using real values in positiveArray. positiveArray is a tuple (indPtr, colInds) :param orderedItems: The ordered items for each user (users are rows, items are cols) :param verbose: If true return precision and first k recommendation for each row, otherwise just precisions """ if type(positiveArray) != tuple: positiveArray = SparseUtils.getOmegaListPtr(positiveArray) orderedItems = orderedItems[:, 0:k] indPtr, colInds = positiveArray precisions = MCEvaluatorCython.precisionAtk(indPtr, colInds, orderedItems) if verbose: return precisions, orderedItems else: return precisions.mean()