# Module: tfr.keras.metrics

<br />

|---|
| [![](https://www.tensorflow.org/images/GitHub-Mark-32px.png) View source on GitHub](https://github.com/tensorflow/ranking/blob/v0.5.3/tensorflow_ranking/python/keras/metrics.py) |

Keras metrics in TF-Ranking.

> [!NOTE]
> **Note:** For metrics that compute a ranking, ties are broken randomly. This means that metrics may be stochastic if items with equal scores are provided.

> [!WARNING]
> **Warning:** Some metrics (e.g. Recall or MRR) are not well-defined when there are no relevant items (e.g. if `y_true` has a row of only zeroes). For these cases, the TF-Ranking metrics will evaluate to `0`.

## Classes

[`class ARPMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/ARPMetric): Average relevance position (ARP).

[`class AlphaDCGMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/AlphaDCGMetric): Alpha discounted cumulative gain (alphaDCG).

[`class DCGMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/DCGMetric): Discounted cumulative gain (DCG).

[`class HitsMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/HitsMetric): Hits@k metric.

[`class MRRMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/MRRMetric): Mean reciprocal rank (MRR).

[`class MeanAveragePrecisionMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/MeanAveragePrecisionMetric): Mean average precision (MAP).

[`class NDCGMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/NDCGMetric): Normalized discounted cumulative gain (NDCG).

[`class OPAMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/OPAMetric): Ordered pair accuracy (OPA).

[`class PrecisionIAMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/PrecisionIAMetric): Precision-IA@k (Pre-IA@k).

[`class PrecisionMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/PrecisionMetric): Precision@k (P@k).

[`class RankingMetricKey`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/RankingMetricKey): Ranking metric key strings.

[`class RecallMetric`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/RecallMetric): Recall@k (R@k).

## Functions

[`default_keras_metrics(...)`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/default_keras_metrics): Returns a list of ranking metrics.

[`get(...)`](https://www.tensorflow.org/ranking/api_docs/python/tfr/keras/metrics/get): Factory method to get a list of ranking metrics.

<br />

<br />

<br />

| ## Other Members ||
|---|---|
| absolute_import | Instance of `__future__._Feature` |
| division | Instance of `__future__._Feature` |
| print_function | Instance of `__future__._Feature` |

<br />