irspack.split.rowwise_train_test_split#
- irspack.split.rowwise_train_test_split(X, test_ratio=0.5, n_test=None, ceil_n_heldout=False, random_state=None)[source]#
Splits the non-zero elements of a sparse matrix into two (train & test interactions). For each row, the ratio of non-zero elements that become the test interaction is (approximately) constant.
- Parameters:
X (csr_matrix | csc_matrix) – The source sparse matrix.
test_ratio (float) – The ratio of test interactions for each row. That is, for each row, if it contains
NNZ-nonzero elements, the number of elements entering into the test interaction will bemath.floor(test_ratio * NNZ). Defaults to 0.5.random_state (None | int | RandomState) – The random state. Defaults to None.
n_test (int | None)
ceil_n_heldout (bool)
- Returns:
A tuple of train & test interactions, which sum back to the original matrix.
- Return type:
Tuple[csr_matrix | csc_matrix, csr_matrix | csc_matrix]