RecommenderBase

class implicit.recommender_base.RecommenderBase

Defines the interface that all recommendations models here expose

fit()

Trains the model on a sparse matrix of item/user/weight

Parameters:item_user (csr_matrix) – A matrix of shape (number_of_items, number_of_users). The nonzero entries in this matrix are the items that are liked by each user. The values are how confident you are that the item is liked by the user.
rank_items()

Rank given items for a user and returns sorted item list.

Parameters:
  • userid (int) – The userid to calculate recommendations for
  • user_items (csr_matrix) – A sparse matrix of shape (number_users, number_items). This lets us look up the liked items and their weights for the user. This is used to filter out items that have already been liked from the output, and to also potentially calculate the best items for this user.
  • selected_items (List of itemids) –
  • recalculate_user (bool, optional) – When true, don’t rely on stored user state and instead recalculate from the passed in user_items
Returns:

List of (itemid, score) tuples. it only contains items that appears in input parameter selected_items

Return type:

list

recommend()

Recommends items for a user

Calculates the N best recommendations for a user, and returns a list of itemids, score.

Parameters:
  • userid (int) – The userid to calculate recommendations for
  • user_items (csr_matrix) – A sparse matrix of shape (number_users, number_items). This lets us look up the liked items and their weights for the user. This is used to filter out items that have already been liked from the output, and to also potentially calculate the best items for this user.
  • N (int, optional) – The number of results to return
  • filter_already_liked_items (bool, optional) – When true, don’t return items present in the training set that were rated by the specificed user.
  • filter_items (sequence of ints, optional) – List of extra item ids to filter out from the output
  • recalculate_user (bool, optional) – When true, don’t rely on stored user state and instead recalculate from the passed in user_items
Returns:

List of (itemid, score) tuples

Return type:

list

similar_items()

Calculates a list of similar items

Parameters:
  • itemid (int) – The row id of the item to retrieve similar items for
  • N (int, optional) – The number of similar items to return
Returns:

List of (itemid, score) tuples

Return type:

list

similar_users()

Calculates a list of similar users

Parameters:
  • userid (int) – The row id of the user to retrieve similar users for
  • N (int, optional) – The number of similar users to return
Returns:

List of (userid, score) tuples

Return type:

list