matchzoo.metrics.mean_reciprocal_rank

Mean reciprocal ranking metric.

Module Contents

class matchzoo.metrics.mean_reciprocal_rank.MeanReciprocalRank(threshold:float=0.0)

Bases: matchzoo.engine.base_metric.RankingMetric

Mean reciprocal rank metric.

ALIAS = ['mean_reciprocal_rank', 'mrr']
__repr__(self)
Returns:Formated string representation of the metric.
__call__(self, y_true:np.array, y_pred:np.array)

Calculate reciprocal of the rank of the first relevant item.

Example

>>> import numpy as np
>>> y_pred = np.asarray([0.2, 0.3, 0.7, 1.0])
>>> y_true = np.asarray([1, 0, 0, 0])
>>> MeanReciprocalRank()(y_true, y_pred)
0.25
Parameters:
  • y_true – The ground true label of each document.
  • y_pred – The predicted scores of each document.
Returns:

Mean reciprocal rank.