recpack.metrics.CoverageK
- class recpack.metrics.CoverageK(K)
Fraction of all items that are ranked among the Top-K recommendations for any user.
Computed as
\[\frac{|\{i \in I | (\exists u \in U) [i \in \text{TopK}(u)] \}|}{|I|}\]- Parameters
K (int) – Size of the recommendation list consisting of the Top-K item predictions.
Methods
calculate
(y_true, y_pred)Computes metric given true labels
y_true
and predicted scoresy_pred
.Attributes
Name of the metric.
Dimension of the item-space in both
y_true
andy_pred
Dimension of the user-space in both
y_true
andy_pred
after elimination of users without interactions iny_true
.Detailed results of the metric.
The global metric value.
- calculate(y_true: scipy.sparse._csr.csr_matrix, y_pred: scipy.sparse._csr.csr_matrix) None
Computes metric given true labels
y_true
and predicted scoresy_pred
. Only Top-K recommendations are considered.Detailed metric results can be retrieved with
results
. Global aggregate metric value is retrieved asvalue
.- 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
andy_pred
- property num_users: int
Dimension of the user-space in both
y_true
andy_pred
after elimination of users without interactions iny_true
.
- property results
Detailed results of the metric.
- property value: float
The global metric value.