--- title: NDCG keywords: fastai sidebar: home_sidebar summary: "Normalized Discounted Cumulative Gain." description: "Normalized Discounted Cumulative Gain." nb_path: "nbs/metrics/ndcg.ipynb" ---
{% raw %}
{% endraw %} {% raw %}
{% endraw %} {% raw %}

ndcg_at_k[source]

ndcg_at_k(y_true_list, y_reco_list, users=None, k=10, next_item=False, all_item=False)

{% endraw %} {% raw %}
{% endraw %} {% raw %}

ndcg_one[source]

ndcg_one(y_true, y_reco, k)

{% endraw %} {% raw %}
{% endraw %} {% raw %}

dcg_at_k[source]

dcg_at_k(r, k, method=0)

Args: r: Relevance scores (list or numpy) in rank order (first element is the first item) k: Number of results to consider method: If 0 then weights are [1.0, 1.0, 0.6309, 0.5, 0.4307, ...] If 1 then weights are [1.0, 0.6309, 0.5, 0.4307, ...] Returns: Discounted cumulative gain

{% endraw %} {% raw %}
{% endraw %} {% raw %}
result = dcg_at_k([3, 2, 3, 0, 1, 2], 6)
result
8.097171433256849
{% endraw %} {% raw %}
assert np.round(result,4)==8.0972
{% endraw %} {% raw %}

ndcg_at_k_v2[source]

ndcg_at_k_v2(r, k, method=0)

{% endraw %} {% raw %}
{% endraw %} {% raw %}
result = ndcg_at_k_v2([3, 2, 3, 0, 1, 2], 6, method=1)
result
0.9608081943360617
{% endraw %} {% raw %}
assert np.round(result,4)==0.9608
{% endraw %}