BaseRecommender

class rsdiv.recommenders.BaseRecommender(df_interaction: DataFrame, items: Optional[DataFrame], test_size: Union[float, int], random_split: bool, user_features: Optional[DataFrame] = None, item_features: Optional[DataFrame] = None, toppop_keep: Optional[ndarray] = None)[source]

Bases: object

Defines a common interface for all recommendation models

Parameters
  • df_interaction (pd.DataFrame) – user/item interaction for train/test.

  • item (pd.DataFrame) – side information for items.

  • test_size (float|int) – indicates whether and how to do the test.

  • random_split (bool) – random split or not.

  • user_features (pd.DataFrame) – user feature columns.

  • item_features (pd.DataFrame) – item feature columns.

get_interaction(df_interaction: DataFrame) Tuple[DataFrame, ndarray, ndarray][source]

The converter for input dataframe

Parameters

df_interaction (pd.DataFrame) – user/item interaction matrix. columns should be [“userId”, “itemId”]

get_user_id(user_string: str) Optional[int][source]

Get the user_id for a given user_string.

Parameters

user_string (str) – Original user string.

Returns

The index of user_id in user_list. Return None it not in training set.

Return type

Optional[int]

get_item_id(item_string: str) Optional[int][source]

Get the item_id for a given item_string.

Parameters

item_string (str) – Original item string.

Returns

The index of item_id in item_list. Return None it not in training set.

Return type

Optional[int]

get_topk_indices(scores: ndarray, top_k: int) ndarray[source]

Get the indices correspond to the topk items.

Parameters
  • scores (np.ndarray) – Scores given by the models.

  • top_k (int) – Numbers of top items to be kept.

Returns

Indices for top_k items.

Return type

np.ndarray