metrax.NDCGAtK#

class metrax.NDCGAtK(total: Array, count: Array)#

Bases: DCGAtK

Computes Normalized Discounted Cumulative Gain at k (NDCG@k) metrics.

NDCG@k normalizes DCG@k by the Ideal DCG@k (IDCG@k), which is the DCG@k score of a perfectly ranked list (items sorted by their true relevance).

This implementation calculates \(NDCG@k\) based on the following formula:

\[NDCG@k = \frac{DCG@k}{IDCG@k}\]

where

  • If \(IDCG@k\) is 0, then \(NDCG@k\) is defined as 0.

  • The \(DCG@k\) calculation uses \(exp2\) gain (\(2^{\text{relevance}} - 1\)) and standard logarithmic discount (\(\frac{1}{\log_2(\text{rank} + 1)}\)).

__init__(total: Array, count: Array) None#

Methods

__init__(total, count)

compute()

Computes final metrics from intermediate values.

compute_value()

Wraps compute() and returns a values.Value.

empty()

Returns an empty instance (i.e. .merge(Metric.empty()) is a no-op).

from_fun(fun)

Calls cls.from_model_output with the return value from fun.

from_model_output(predictions, labels, ks)

Creates a DCGAtK metric instance from model output.

from_output(name)

Calls cls.from_model_output with model output named name.

merge(other)

Returns Metric that is the accumulation of self and other.

reduce()

Reduces the metric along it first axis by calling _reduce_merge().

replace(**updates)

Returns a new object replacing the specified fields with new values.

Attributes

total

count

__init__(total: Array, count: Array) None#
replace(**updates)#

Returns a new object replacing the specified fields with new values.