irspack.split.UserTrainTestInteractionPair

class irspack.split.UserTrainTestInteractionPair(user_ids, X_train, X_test, item_ids=None)[source]

Bases: object

A class to hold users’ train & test (if any) interactions and their ids.

Parameters:
  • user_ids (Union[List[Any], ndarray]) – List of user ids. Its i-th element should correspond to i-th row of X_train.

  • X_train (csr_matrix) – The train part of interactions.

  • X_test (csr_matrix) – The test part of interactions (if any). If None, an empty matrix with the shape of X_train will be created. Defaults to None.

  • item_ids (Optional[Union[List[Any], ndarray]]) –

Raises:
  • ValueError – when X_train and user_ids have inconsistent size.

  • ValueError – when X_train and X_test have inconsistent size.

__init__(user_ids, X_train, X_test, item_ids=None)[source]
Parameters:
  • user_ids (Union[List[Any], ndarray]) –

  • X_train (Union[csr_matrix, csc_matrix]) –

  • X_test (Optional[Union[csr_matrix, csc_matrix]]) –

  • item_ids (Optional[Union[List[Any], ndarray]]) –

Methods

__init__(user_ids, X_train, X_test[, item_ids])

concat(other)

Concatenate the users data.

df_test()

df_train()

Attributes

X_train

The train part of users' interactions.

X_test

The test part of users' interactions.

n_users

The number of users

n_items

The number of items

X_all

If X_test is not None, equal to X_train + X_test.Otherwise equals X_train.

X_all: csr_matrix

If X_test is not None, equal to X_train + X_test.Otherwise equals X_train.

X_test: csr_matrix

The test part of users’ interactions.

X_train: csr_matrix

The train part of users’ interactions.

concat(other)[source]

Concatenate the users data. user_id will be self.user_ids + self.item_ids.

Returns:

[description]

Return type:

[type]

Parameters:

other (UserTrainTestInteractionPair) –

ValueError:

when self and other have unequal n_items.

n_items: int

The number of items

n_users: int

The number of users