corneto.ml.kfold_nonzero_splits#

corneto.ml.kfold_nonzero_splits(data, n_splits=5, shuffle=True, random_state=42)#

Perform K-fold splitting on all nonzero cells in the input data.

Splits all nonzero cells in the input data, returning two structures per fold (train and val), each the same shape as the original data, but with NaNs (or a numpy.nan equivalent) marking the ‘left-out’ entries.

Parameters:
  • data (array-like or pd.DataFrame) – Input data with shape (features x samples) and values in {-1, 0, 1}. Can be a numpy array or a pandas DataFrame.

  • n_splits (int, optional) – Number of folds (default=5).

  • shuffle (bool, optional) – Shuffle the labeled cells before splitting (default=True).

  • random_state (int, optional) – Random seed for reproducibility (default=42).

  • Returns

  • ------

  • train (tuple of the same type as data) –

    • Both have the same shape as data.

    • In train, all cells that belong to the validation fold are set to NaN.

    • In val, all cells that are not in the validation fold are set to NaN.

  • val (tuple of the same type as data) –

    • Both have the same shape as data.

    • In train, all cells that belong to the validation fold are set to NaN.

    • In val, all cells that are not in the validation fold are set to NaN.