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 (Union[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 (Union[None, int, RandomState]) – The random state. Defaults to None.
n_test (Optional[int]) –
ceil_n_heldout (bool) –
- Returns:
A tuple of train & test interactions, which sum back to the original matrix.
- Return type:
Tuple[Union[csr_matrix, csc_matrix], Union[csr_matrix, csc_matrix]]