Interactions

Module with functionality for splitting and shuffling datasets.

spotlight.cross_validation.random_train_test_split(interactions, test_percentage=0.2, random_state=None)[source]

Randomly split interactions between training and testing.

Parameters
  • interactions (spotlight.interactions.Interactions) – The interactions to shuffle.

  • test_percentage (float, optional) – The fraction of interactions to place in the test set.

  • random_state (np.random.RandomState, optional) – The random state used for the shuffle.

Returns

(train, test)spotlight.interactions.Interactions) A tuple of (train data, test data)

Return type

(spotlight.interactions.Interactions,

spotlight.cross_validation.shuffle_interactions(interactions, random_state=None)[source]

Shuffle interactions.

Parameters
  • interactions (spotlight.interactions.Interactions) – The interactions to shuffle.

  • random_state (np.random.RandomState, optional) – The random state used for the shuffle.

Returns

interactions – The shuffled interactions.

Return type

spotlight.interactions.Interactions

spotlight.cross_validation.user_based_train_test_split(interactions, test_percentage=0.2, random_state=None)[source]

Split interactions between a train and a test set based on user ids, so that a given user’s entire interaction history is either in the train, or the test set.

Parameters
  • interactions (spotlight.interactions.Interactions) – The interactions to shuffle.

  • test_percentage (float, optional) – The fraction of users to place in the test set.

  • random_state (np.random.RandomState, optional) – The random state used for the shuffle.

Returns

(train, test)spotlight.interactions.Interactions) A tuple of (train data, test data)

Return type

(spotlight.interactions.Interactions,