Interactions
- class rectools.dataset.interactions.Interactions(df: DataFrame)[source]
Bases:
object
Structure to store info about user-item interactions.
Usually it’s more convenient to use from_raw method instead of direct creating.
- Parameters
df (pd.DataFrame) –
- Table where every row contains user-item interaction and columns are:
Columns.User - internal user id (non-negative int values);
Columns.Item - internal item id (non-negative int values);
Columns.Weight - weight of interaction, float, use
1
if interactions have no weight;Columns.Datetime - timestamp of interactions, assign random value if you’re not going to use it later.
- Inherited-members
Methods
from_raw
(interactions, user_id_map, item_id_map)Create Interactions from dataset with external ids and id mappings.
get_user_item_matrix
([include_weights])Form a user-item CSR matrix based on interactions data.
to_external
(user_id_map, item_id_map[, ...])Convert itself to pd.DataFrame with replacing internal user and item ids to external ones.
Attributes
df
- classmethod from_raw(interactions: DataFrame, user_id_map: IdMap, item_id_map: IdMap) Interactions [source]
Create Interactions from dataset with external ids and id mappings.
- Parameters
interactions (pd.DataFrame) –
- Table where every row contains user-item interaction and columns are:
Columns.User - user id;
Columns.Item - item id;
Columns.Weight - weight of interaction, float, use
1
if interactions have no weight;Columns.Datetime - timestamp of interactions, assign random value if you’re not going to use it later.
user_id_map (IdMap) – User identifiers mapping.
item_id_map (IdMap) – Item identifiers mapping.
- Return type
- get_user_item_matrix(include_weights: bool = True) csr_matrix [source]
Form a user-item CSR matrix based on interactions data.
- Parameters
include_weights (bool, default
True
) – Whether include interaction weights in matrix or not. IfFalse
, all values in returned matrix will be equal to1
.- Return type
csr_matrix
- to_external(user_id_map: IdMap, item_id_map: IdMap, include_weight: bool = True, include_datetime: bool = True) DataFrame [source]
Convert itself to pd.DataFrame with replacing internal user and item ids to external ones.
- Parameters
user_id_map (IdMap) – User id map that has to be used for converting internal user ids to external ones.
item_id_map (IdMap) – Item id map that has to be used for converting internal item ids to external ones.
include_weight (bool, default
True
) – Whether to include weight column into resulting table or notinclude_datetime (bool, default
True
) – Whether to include datetime column into resulting table or not.
- Return type
pd.DataFrame