recpack.metrics.PercentileRanking

class recpack.metrics.PercentileRanking

Expected Percentile Ranking.

Metric as described in Hu, Yifan, Yehuda Koren, and Chris Volinsky. “Collaborative filtering for implicit feedback datasets.” 2008 Eighth IEEE International Conference on Data Mining. Ieee, 2008. With a change to account for items that receive no recommendation score for a user.

Percentile ranking is calculated according to the following formula:

\[\text{perc_rank} = \frac{\sum\limits_{u \in U,i \in I} y^{true}_{u,i} * \overline{\text{rank}}_{u,i}}{\sum\limits_{u \in U,i \in I} y^{true}_{u,i}}\]

where

\[\begin{split}\overline{rank}_{u,i} = \begin{cases} \frac{\text{rank}_{u,i} - 1}{|I|} & \text{if } i \in y^{pred}(u) \\ \frac{\max\limits_{j} (\text{rank}_{uj}) + |I|}{2|I|} & \text{otherwise} \end{cases}\end{split}\]

Non predicted items in the \(y^{true}\) matrix, get the average rank from all remaining items per user. As if these remaining items would be ordered randomly.

Lower values of this percentile-ranking are desirable, because that indicates relevant items are shown at higher positions.

Methods

calculate(y_true, y_pred)

Calculates this metric for all nonzero users in y_true, given true labels and predicted scores.

Attributes

name

Name of the metric.

num_items

Dimension of the item-space in both y_true and y_pred

num_users

Dimension of the user-space in both y_true and y_pred after elimination of users without interactions in y_true.

results

Detailed results of the metric.

value

The global metric value.

calculate(y_true: scipy.sparse._csr.csr_matrix, y_pred: scipy.sparse._csr.csr_matrix) None

Calculates this metric for all nonzero users in y_true, given true labels and predicted scores.

Parameters
  • y_true (csr_matrix) – True user-item interactions.

  • y_pred (csr_matrix) – Predicted affinity of users for items.

property name

Name of the metric.

property num_items: int

Dimension of the item-space in both y_true and y_pred

property num_users: int

Dimension of the user-space in both y_true and y_pred after elimination of users without interactions in y_true.

property results

Detailed results of the metric.

property value: float

The global metric value.