def dcg_score(y_true, y_score, k=10, gains='exponential'):
    'Discounted cumulative gain (DCG) 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    DCG @k : float\n    '
    order = np.argsort(y_score)[::(- 1)]
    y_true = np.take(y_true, order[:k])
    if (gains == 'exponential'):
        gains = ((2 ** y_true) - 1)
    elif (gains == 'linear'):
        gains = y_true
    else:
        raise ValueError('Invalid gains option.')
    discounts = np.log2((np.arange(len(y_true)) + 2))
    return np.sum((gains / discounts))
Discounted cumulative gain (DCG) 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
-------
DCG @k : float
def dcg_score(y_true, y_score, k=10, gains='exponential'):
    'Discounted cumulative gain (DCG) 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    DCG @k : float\n    '
    order = np.argsort(y_score)[::(- 1)]
    y_true = np.take(y_true, order[:k])
    if (gains == 'exponential'):
        gains = ((2 ** y_true) - 1)
    elif (gains == 'linear'):
        gains = y_true
    else:
        raise ValueError('Invalid gains option.')
    discounts = np.log2((np.arange(len(y_true)) + 2))
    return np.sum((gains / discounts))