def mean_ndcg_score(y_true, y_score, k=10, gains='exponential'):
    'Normalized discounted cumulative gain (NDCG) at rank k\n    Parameters\n    ----------\n    y_true : array-like, shape = [n_samples]\n        Ground truth (true relevance labels).\n    y_score : array-like, shape = [n_samples]\n        Predicted scores.\n    k : int\n        Rank.\n    gains : str\n        Whether gains should be "exponential" (default) or "linear".\n    Returns\n    -------\n    Mean NDCG @k : float\n    '
    ndcg_s = []
    for (y_t, y_s) in zip(y_true, y_score):
        if np.sum((y_t == 1)):
            ndcg_s.append(ndcg_score(y_t, y_s, k=k, gains=gains))
    return np.mean(ndcg_s)
Normalized discounted cumulative gain (NDCG) at rank k
Parameters
----------
y_true : array-like, shape = [n_samples]
    Ground truth (true relevance labels).
y_score : array-like, shape = [n_samples]
    Predicted scores.
k : int
    Rank.
gains : str
    Whether gains should be "exponential" (default) or "linear".
Returns
-------
Mean NDCG @k : float
def mean_ndcg_score(y_true, y_score, k=10, gains='exponential'):
    'Normalized discounted cumulative gain (NDCG) at rank k\n    Parameters\n    ----------\n    y_true : array-like, shape = [n_samples]\n        Ground truth (true relevance labels).\n    y_score : array-like, shape = [n_samples]\n        Predicted scores.\n    k : int\n        Rank.\n    gains : str\n        Whether gains should be "exponential" (default) or "linear".\n    Returns\n    -------\n    Mean NDCG @k : float\n    '
    ndcg_s = []
    for (y_t, y_s) in zip(y_true, y_score):
        if np.sum((y_t == 1)):
            ndcg_s.append(ndcg_score(y_t, y_s, k=k, gains=gains))
    return np.mean(ndcg_s)