Prediction utilities with NA handling.
Functions:
| Name | Description |
|---|---|
fill_valid | Fill valid positions in result array with computed values. |
get_valid_rows | Identify valid (non-NA) rows in a design matrix. |
init_na_array | Create an array of NaN values. |
Functions¶
fill_valid¶
fill_valid(result: NDArray, valid_mask: NDArray[np.bool_], values: NDArray) -> NDArrayFill valid positions in result array with computed values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result | NDArray | Array to fill (modified in place), shape (n,). | required |
valid_mask | NDArray[bool_] | Boolean mask indicating valid positions, shape (n,). | required |
values | NDArray | Values to insert at valid positions, shape (n_valid,). | required |
Returns:
| Type | Description |
|---|---|
NDArray | The result array (same object, modified in place). |
Examples:
>>> result = np.full(3, np.nan)
>>> valid_mask = np.array([True, False, True])
>>> values = np.array([10.0, 20.0])
>>> fill_valid(result, valid_mask, values)
array([10., nan, 20.])get_valid_rows¶
get_valid_rows(X: NDArray) -> tuple[NDArray[np.bool_], NDArray, int]Identify valid (non-NA) rows in a design matrix.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
X | NDArray | Design matrix of shape (n, p), may contain NaN values. | required |
Returns:
| Type | Description |
|---|---|
NDArray[bool_] | Tuple of (valid_mask, X_valid, n) where: |
NDArray | - valid_mask: Boolean array of shape (n,), True for rows without NaN |
int | - X_valid: Design matrix with only valid rows, shape (n_valid, p) |
tuple[NDArray[bool_], NDArray, int] | - n: Total number of rows |
Examples:
>>> X = np.array([[1, 2], [np.nan, 3], [4, 5]])
>>> valid_mask, X_valid, n = get_valid_rows(X)
>>> valid_mask
array([ True, False, True])
>>> X_valid
array([[1., 2.], [4., 5.]])init_na_array¶
init_na_array(n: int, dtype: type = np.float64) -> NDArrayCreate an array of NaN values.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Length of array. | required |
dtype | type | Data type (default float64). | float64 |
Returns:
| Type | Description |
|---|---|
NDArray | Array of NaN values with shape (n,). |