recommend_from_scores

rectools.models.utils.recommend_from_scores(scores: ndarray, k: int, sorted_blacklist: Optional[ndarray] = None, sorted_whitelist: Optional[ndarray] = None, ascending: bool = False) Tuple[ndarray, ndarray][source]

Prepare top-k recommendations for a user.

Recommendations are sorted by item scores for this particular user. Recommendations can be filtered according to whitelist and blacklist.

If I - set of all items, B - set of blacklist items, W - set of whitelist items, then:
  • if W is None, then for recommendations will be used I - B set of items

  • if W is not None, then for recommendations will be used W - B set of items

Parameters
  • scores (np.ndarray) – Array of floats. Scores of relevance of all items for this user. Shape (n_items,).

  • k (int) – Desired number of final recommendations. If, after applying white- and blacklist, number of available items n_available is less than k, then n_available items will be returned without warning.

  • sorted_blacklist (np.ndarray, optional, default None) – Array of unique ints. Sorted inner item ids to exclude from recommendations.

  • sorted_whitelist (np.ndarray, optional, default None) – Array of unique ints. Sorted inner item ids to use in recommendations.

  • ascending (bool, default False) – If False, sorting by descending of score, use when score are metric of similarity. If True, sorting by ascending of score, use when score are distance.

Returns

Array of recommended items, sorted by score descending.

Return type

np.ndarray