Utils¶
-
recoder.utils.
normalize
(x, axis=None)[source]¶ Returns the normalization of x along axis.
Parameters: - x (np.array) – matrix or vector
- axis (int, optional) – the axis along which to compute the normalization
-
recoder.utils.
dataframe_to_csr_matrix
(dataframe, user_col, item_col, inter_col, item_id_map=None, user_id_map=None)[source]¶ Converts a
pandas.DataFrame
of users and items interactions into ascipy.sparse.csr_matrix
.This function returns a tuple of the interactions sparse matrix, a dict that maps from original item ids in the dataframe to the 0-based item ids, and similarly a dict that maps from original user ids in the dataframe to the 0-based user ids.
Parameters: - dataframe (pandas.DataFrame) – A dataframe containing users and items interactions
- user_col (str) – users column name
- item_col (str) – items column name
- inter_col (str) – user-item interaction value column name
- item_id_map (dict, optional) – A dictionary mapping from original item ids into 0-based item ids. If not given, the map will be generated using the items column in the dataframe
- user_id_map (dict, optional) – A dictionary mapping from original user ids into 0-based user ids. If not given, the map will be generated using the users column in the dataframe
Returns: A tuple of the csr_matrix, a
dict
item_id_map, and adict
user_id_mapReturn type: tuple