Skip to content

LinkPredDiversity

LinkPredDiversity(k: int, category: ArrayLike)

Bases: _LinkPredMetric

Diversity @ \(k\) of the recommendations according to item categories,

\[ div_{u@k} = 1 - \left( \frac{1}{k \cdot (k-1)} \right) \sum_{i \neq j} sim(i, j) \]

where \(sim(i, j)\) is 1 if items \(i\) and \(j\) share their category and 0 otherwise.

Parameters:

Name Type Description Default
k int

The number of top-\(k\) predictions to evaluate against.

required
category ArrayLike

The category of every destination node.

required
Source code in mlx_graphs/metrics/link_pred.py
def __init__(self, k: int, category: ArrayLike):
    self.category = _host(category)
    super().__init__(k)

from mlx_graphs.metrics import LinkPredDiversity · mlx_graphs/metrics/link_pred.py