FMRecommender

class rsdiv.recommenders.FMRecommender(interaction: DataFrame, items: Optional[DataFrame], test_size: Union[float, int] = 0.3, random_split: bool = True, no_components: int = 10, item_alpha: float = 0, user_alpha: float = 0, loss: str = 'bpr')[source]

Bases: BaseRecommender

FM recommender based on LightFM.

Parameters
  • interaction (pd.DataFrame) – user-item interaction matrix.

  • items (Optional[pd.DataFrame]) – item side information.

  • no_components (int) – the dimensions of user/item embeddings.

  • item_alpha (float) – L2 penalty on item features.

  • user_alpha (float) – L2 penalty on user features.

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

The converter for input dataframe

Parameters

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

get_item_id(item_string: str) Optional[int]

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

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

get_user_id(user_string: str) Optional[int]

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]