def apk(y_true, y_pred, k=10, normalize='min'):
    """
        Computes the average precision at k.
        This function computes the average precision at k between two lists of
        items.
                Parameters:
                            y_true: list
                                    A list of elements that are to be predicted (order doesn't matter)
                            y_pred: list
                                    A list of predicted elements (order does matter)
                            k: int, optional
                                The maximum number of predicted elements
                            normalize: type of normalize
                                'k': normalize by top k
                                'm': normalize by number of relevant documents (length of y_true)
                                'min': normalize by min(m,k)
                Returns
                            score : double
                                The average precision at k over the input lists
    """
    assert normalize in ['k', 'm', 'min'], "normalize should be in ['k', 'm', min']"
    if not y_true or not y_pred:
        return 0.0
    if len(y_pred) > k:
        y_pred = y_pred[:k]

    score = 0.0
    num_hits = 0.0

    for i, p in enumerate(y_pred):
        if p in y_true:
            num_hits += 1.0
            p_at_k = num_hits / (i + 1.0)
            score += p_at_k * 1  # (p@k * rel(k))

    if normalize == 'k':
        score = score / k
    elif normalize == 'm':
        score = score / len(y_true)
    else:
        score = score / min(len(y_true), k)
    return score