Utilities¶
make_xprobe_mask ¶
make_xprobe_mask(x: InputMatrix, fraction: float = 0.1, rng: Generator | None = None, *, mask: InputMask | None = None, compat_mode: str | CompatMode = CompatMode.MODERN) -> tuple[Float64Array | sp.csr_matrix, Float64Array | sp.csr_matrix]
Hold out a fraction of observed entries as probe data.
Selects a random subset of observed entries (non-NaN for dense, stored non-NaN entries for sparse) and returns a modified data matrix with those entries masked out plus a probe matrix containing only the held-out values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
InputMatrix
|
Two-dimensional dense or sparse data. The returned matrices keep the same orientation; use the layout required by the consuming API. |
required |
fraction
|
float
|
Fraction of observed entries to hold out (default 0.10).
Must be in |
0.1
|
rng
|
Generator | None
|
NumPy random generator. If |
None
|
mask
|
InputMask | None
|
Optional observation mask. When supplied, probe entries are sampled only from positions marked observed, including explicitly stored zero values in sparse data. This restricts probe sampling; unselected entries outside the mask remain in the returned training copy. |
None
|
compat_mode
|
str | CompatMode
|
|
MODERN
|
Returns:
| Name | Type | Description |
|---|---|---|
x_masked |
Float64Array | csr_matrix
|
Copy of x with probe entries set to NaN (dense) or removed (sparse). |
xprobe |
Float64Array | csr_matrix
|
Matrix of the same shape as x containing only the held-out probe values; all other entries are NaN (dense) or absent (sparse). |
Raises:
| Type | Description |
|---|---|
ValueError
|
If fraction is not in |
TypeError
|
If the mode is not a string. |