#NEWLINE# def kdd_mapk( actual , predicted , k = 10 ) : #NEWLINE# #INDENT# "\n    Computes the mean average precision at k for Track 1 of the 2012 KDD Cup.\n\n    This modified version uses the number of actual clicks as the denominator,\n    regardless of k.\n\n    This function computes the mean average prescision at k between two lists\n    of lists of items.\n\n    Parameters\n    ----------\n    actual : list\n             A list of lists of elements that are to be predicted \n             (order doesn't matter in the lists)\n    predicted : list\n                A list of lists of predicted elements\n                (order matters in the lists)\n    k : int, optional\n        The maximum number of predicted elements\n\n    Returns\n    -------\n    score : double\n            The mean average precision at k over the input lists\n\n    " #NEWLINE# return np . mean ( [ kdd_apk ( a , p , k ) for ( a , p ) in zip ( actual , predicted ) ] )