recpack.metrics.ReciprocalRankK
- class recpack.metrics.ReciprocalRankK(K)
- Computes the inverse of the rank of the first hit in the recommendation list. - The reciprocal rank for a user is calculated as \[\begin{split}\text{ReciprocalRank}(u) = \frac{1}{\min\limits_{i \in \text{Top-K}(u), \\ i \in y^{true}_u} rank(u,i)}\end{split}\]- when there is at least one matching item between recommendations in \(\text{Top-K}(u)\) and targets in \(y^{true}_u\), otherwise it is 0. - Parameters
- K (int) – Amount of top recommendations to consider in the metric calculation. 
 - Methods - calculate(y_true, y_pred)- Computes metric given true labels - y_trueand predicted scores- y_pred.- Attributes - The names of the columns in the results DataFrame. - Name of the metric. - Dimension of the item-space in both - y_trueand- y_pred- Dimension of the user-space in both - y_trueand- y_predafter elimination of users without interactions in- y_true.- Get the detailed results for this metric. - Global metric value obtained by taking the average over all users. - calculate(y_true: scipy.sparse._csr.csr_matrix, y_pred: scipy.sparse._csr.csr_matrix) None
- Computes metric given true labels - y_trueand predicted scores- y_pred. Only Top-K recommendations are considered.- Detailed metric results can be retrieved with - results. Global aggregate metric value is retrieved as- value.- Parameters
- y_true (csr_matrix) – True user-item interactions. 
- y_pred (csr_matrix) – Predicted affinity of users for items. 
 
 
 - property col_names
- The names of the columns in the results DataFrame. 
 - property name
- Name of the metric. 
 - property num_items: int
- Dimension of the item-space in both - y_trueand- y_pred
 - property num_users: int
- Dimension of the user-space in both - y_trueand- y_predafter elimination of users without interactions in- y_true.
 - property results
- Get the detailed results for this metric. - Contains an entry for every user. - Returns
- The results DataFrame with columns: user_id, score 
- Return type
- pd.DataFrame 
 
 - property value
- Global metric value obtained by taking the average over all users.