# tfma.metrics.NDCG

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/model-analysis/blob/v0.46.0/tensorflow_model_analysis/metrics/ndcg.py#L28-L61) |

NDCG (normalized discounted cumulative gain) metric.

Inherits From: [`Metric`](https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/metrics/Metric)

    tfma.metrics.NDCG(
        gain_key: str,
        top_k_list: Optional[List[int]] = None,
        name: str = NDCG_NAME
    )

Calculates NDCG@k for a given set of top_k values calculated from a list of
gains (relevance scores) that are sorted based on the associated predictions.
The top_k_list can be passed as part of the NDCG metric config or using
tfma.MetricsSpec.binarize.top_k_list if configuring multiple top_k metrics.
The gain (relevance score) is determined from the value stored in the
'gain_key' feature. The value of NDCG@k returned is a weighted average of
NDCG@k over the set of queries using the example weights.

NDCG@k = (DCG@k for the given rank)/(DCG@k
DCG@k = sum_{i=1}\^k gain_i/log_2(i+1), where gain_i is the gain (relevance
score) of the i\^th ranked response, indexed from 1.

This is a query/ranking based metric so a query_key must also be provided in
the associated tfma.MetricsSpec.

<br />

<br />

<br />

| ## Args ||
|---|---|
| `gain_key` | Key of feature in features dictionary that holds gain values. |
| `top_k_list` | Values for top k. This can also be set using the tfma.MetricsSpec.binarize.top_k_list associated with the metric. |
| `name` | Metric name. |

<br />

<br />

<br />

<br />

| ## Attributes ||
|---|---|
| `compute_confidence_interval` | Whether to compute confidence intervals for this metric. <br /> Note that this may not completely remove the computational overhead involved in computing a given metric. This is only respected by the jackknife confidence interval method. |

<br />

## Methods

### `computations`

[View source](https://github.com/tensorflow/model-analysis/blob/v0.46.0/tensorflow_model_analysis/metrics/metric_types.py#L862-L888)

    computations(
        eval_config: Optional[https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/EvalConfig] = None,
        schema: Optional[schema_pb2.Schema] = None,
        model_names: Optional[List[str]] = None,
        output_names: Optional[List[str]] = None,
        sub_keys: Optional[List[Optional[SubKey]]] = None,
        aggregation_type: Optional[AggregationType] = None,
        class_weights: Optional[Dict[int, float]] = None,
        example_weighted: bool = False,
        query_key: Optional[str] = None
    ) -> https://www.tensorflow.org/tfx/model_analysis/api_docs/python/tfma/metrics/MetricComputations

Creates computations associated with metric.

### `from_config`

[View source](https://github.com/tensorflow/model-analysis/blob/v0.46.0/tensorflow_model_analysis/metrics/metric_types.py#L842-L847)

    @classmethod
    from_config(
        config: Dict[str, Any]
    ) -> 'Metric'

### `get_config`

[View source](https://github.com/tensorflow/model-analysis/blob/v0.46.0/tensorflow_model_analysis/metrics/metric_types.py#L838-L840)

    get_config() -> Dict[str, Any]

Returns serializable config.