Interactions

class rectools.dataset.interactions.Interactions(df: DataFrame)[source]

Bases: object

Structure to storage 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 an user-item CSR matrix based on interactions attribute.

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

Interactions

get_user_item_matrix(include_weights: bool = True) csr_matrix[source]

Form an user-item CSR matrix based on interactions attribute.

It is used Interactions.get_user_item_matrix, see its documentations for details.

Parameters

include_weights (bool, default True) – Whether include interaction weights in matrix or not. If False, all values in returned matrix will be equal to 1.

Return type

csr_matrix