Utilities¶
make_xprobe_mask ¶
make_xprobe_mask(x: ndarray | csr_matrix, fraction: float = 0.1, rng: Generator | None = None) -> tuple[np.ndarray | sp.csr_matrix, np.ndarray | sp.csr_matrix]
Hold out a fraction of observed entries as probe data.
Selects a random subset of observed entries (non-NaN for dense, structurally non-zero for sparse) and returns a modified data matrix with those entries masked out plus a probe matrix containing only the held-out values.
Args:
x: Data matrix of shape (n_features, n_samples).
Dense or sparse (CSR).
fraction: Fraction of observed entries to hold out (default 0.10).
Must be in (0, 1).
rng: NumPy random generator. If None, a new default generator
is created.
Returns: x_masked: Copy of x with probe entries set to NaN (dense) or removed (sparse). xprobe: Matrix of the same shape as x containing only the held-out probe values; all other entries are NaN (dense) or absent (sparse).
Raises:
ValueError: If fraction is not in (0, 1).