Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Prediction utilities with NA handling.

Functions:

NameDescription
fill_validFill valid positions in result array with computed values.
get_valid_rowsIdentify valid (non-NA) rows in a design matrix.
init_na_arrayCreate an array of NaN values.

Functions

fill_valid

fill_valid(result: NDArray, valid_mask: NDArray[np.bool_], values: NDArray) -> NDArray

Fill valid positions in result array with computed values.

Parameters:

NameTypeDescriptionDefault
resultNDArrayArray to fill (modified in place), shape (n,).required
valid_maskNDArray[bool_]Boolean mask indicating valid positions, shape (n,).required
valuesNDArrayValues to insert at valid positions, shape (n_valid,).required

Returns:

TypeDescription
NDArrayThe 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:

NameTypeDescriptionDefault
XNDArrayDesign matrix of shape (n, p), may contain NaN values.required

Returns:

TypeDescription
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) -> NDArray

Create an array of NaN values.

Parameters:

NameTypeDescriptionDefault
nintLength of array.required
dtypetypeData type (default float64).float64

Returns:

TypeDescription
NDArrayArray of NaN values with shape (n,).