Dataset splitting functions.

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

Randomly split interactions between training and testing.

This function takes an interaction set and splits it into two disjoint sets, a training set and a test set. Note that no effort is made to make sure that all items and users with interactions in the test set also have interactions in the training set; this may lead to a partial cold-start problem in the test set.

  • interactions (a scipy sparse matrix containing interactions) – The interactions to split.
  • 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.

(train, test) – scipy.sparse.COOMatrix) A tuple of (train data, test data)

Return type: