Missing Value Imputers
Univariate, k-NN, iterative MICE imputation, and missingness indicators in ochreml.impute (SimpleImputer, MissingIndicator, KNNImputer, IterativeImputer).
ochreml.impute provides four missing-value transformers (also lazily importable from ochreml), spanning fast univariate statistics, distance-weighted k-Nearest Neighbors, and multivariate chained-equation (MICE) imputation. All four classes support .dit persistence. (^▽^)
Overview
| Class | Strategy | Supports Categoricals | add_indicator | .dit Tag |
|---|---|---|---|---|
SimpleImputer | Per-feature mean, median, most_frequent, constant | Yes (most_frequent, constant) | Yes | 25 |
MissingIndicator | Binary boolean mask of missing positions | Numeric buffers | N/A | 26 |
KNNImputer | Multivariate nan_euclidean k-Nearest Neighbors | No (numeric) | Yes | 27 |
IterativeImputer | Multivariate round-robin regression (default: OchreML Ridge) | No (numeric) | Yes | 34 |
SimpleImputer
Univariate imputer backed by Rust column reduction (mean) and Rayon kernels (median, most_frequent, constant). All constructor parameters are keyword-only.
from ochreml.impute import SimpleImputer
imp = SimpleImputer(
missing_values=float("nan"),
strategy="mean",
fill_value=None,
copy=True,
add_indicator=False,
keep_empty_features=False,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
missing_values | int | float | str | None | nan | nan | Placeholder value treated as missing. |
strategy | {"mean", "median", "most_frequent", "constant"} | "mean" | Imputation strategy per feature. |
fill_value | Any | None | None | Replacement value used when strategy="constant". |
copy | bool | True | Kept for scikit-learn parity; returns a new array. |
add_indicator | bool | False | If True, stacks a MissingIndicator matrix onto the output columns. |
keep_empty_features | bool | False | If True, retains all-missing columns instead of dropping them. |
device | str | None | None | Target compute device. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),transform(X),fit_transform(X, y=None),inverse_transform(X)(requiresadd_indicator=True),save(path),load(path, device=None),to(device) - Attributes:
statistics_,n_features_in_,device_
import numpy as np
from ochreml.impute import SimpleImputer
X = np.array([[1.0, np.nan], [3.0, 2.0], [np.nan, 4.0]])
imp = SimpleImputer(strategy="median", add_indicator=True)
X_filled = imp.fit_transform(X)
X_restored = imp.inverse_transform(X_filled)MissingIndicator
Generates binary boolean columns marking where missing_values appear in X. All constructor parameters are keyword-only.
from ochreml.impute import MissingIndicator
ind = MissingIndicator(
missing_values=float("nan"),
features="missing-only",
sparse="auto",
error_on_new=True,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
missing_values | float | nan | Placeholder for missing values. |
features | {"missing-only", "all"} | "missing-only" | Emit indicators for all features or only features that had missing values at fit time. |
sparse | {"auto", True, False} | "auto" | Returns scipy.sparse.csr_matrix when True; dense bool ndarray otherwise. |
error_on_new | bool | True | Raise ValueError if features="missing-only" and previously complete features have missing values at transform. |
device | str | None | None | Target compute device. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),transform(X),fit_transform(X, y=None),get_feature_names_out(input_features=None),save(path),load(path, device=None),to(device) - Attributes:
features_(indices of represented columns),n_features_in_,device_
KNNImputer
Multivariate imputer that fills each missing entry using the mean (uniform or distance-weighted) of the n_neighbors nearest rows under the nan_euclidean distance metric, accelerated by Rust hardware backend pairwise distance and top-k kernels. All constructor parameters are keyword-only.
from ochreml.impute import KNNImputer
knn_imp = KNNImputer(
missing_values=float("nan"),
n_neighbors=5,
weights="uniform",
metric="nan_euclidean",
copy=True,
add_indicator=False,
keep_empty_features=False,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
missing_values | float | nan | Placeholder for missing values. |
n_neighbors | int | 5 | Number of neighboring samples used to impute each missing entry. |
weights | {"uniform", "distance"} | "uniform" | Weighting scheme for neighbor values. |
metric | {"nan_euclidean"} | "nan_euclidean" | Pairwise distance metric handling missing entries. |
copy | bool | True | Kept for scikit-learn parity. |
add_indicator | bool | False | If True, appends missingness indicator columns. |
keep_empty_features | bool | False | If True, retains all-missing columns. |
device | str | None | None | Target compute device ("auto", "cpu", "cuda:0", "wgpu", "tpu:0"). |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),transform(X),fit_transform(X, y=None),save(path),load(path, device=None),to(device) - Attributes:
n_features_in_,device_
IterativeImputer
Multivariate chained-equation (MICE) imputer that models each feature with missing values as a function of the other features in round-robin passes. Defaults to OchreML's hardware-accelerated Ridge(alpha=1.0) when estimator=None.
from ochreml.impute import IterativeImputer
it_imp = IterativeImputer(
estimator=None,
missing_values=float("nan"),
sample_posterior=False,
max_iter=10,
tol=1e-3,
n_nearest_features=None,
initial_strategy="mean",
fill_value=None,
imputation_order="ascending",
skip_complete=False,
min_value=float("-inf"),
max_value=float("inf"),
verbose=0,
random_state=None,
add_indicator=False,
keep_empty_features=False,
device=None,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
estimator | regressor or None | None | Regressor fitted at each round-robin step (defaults to ochreml.Ridge(alpha=1.0)). |
missing_values | float | nan | Keyword-only; placeholder for missing values. |
sample_posterior | bool | False | Keyword-only; kept for API compatibility. |
max_iter | int | 10 | Keyword-only; maximum number of round-robin passes. |
tol | float | 1e-3 | Keyword-only; relative convergence stopping tolerance. |
n_nearest_features | int | None | None | Keyword-only; number of highest-correlation features used to predict each column (None uses all). |
initial_strategy | {"mean", "median", "most_frequent", "constant"} | "mean" | Keyword-only; strategy for initial SimpleImputer pass. |
fill_value | float | None | None | Keyword-only; constant fill value when initial_strategy="constant". |
imputation_order | {"ascending", "descending", "roman", "arabic", "random"} | "ascending" | Keyword-only; column ordering for each round-robin pass. |
skip_complete | bool | False | Keyword-only; skip columns with no missing values during fit. |
min_value | float | array-like | -inf | Keyword-only; lower clipping bound(s) for imputed values. |
max_value | float | array-like | +inf | Keyword-only; upper clipping bound(s) for imputed values. |
verbose | int | 0 | Keyword-only; verbosity level. |
random_state | int | None | None | Keyword-only; random seed for imputation_order="random". |
add_indicator | bool | False | Keyword-only; append MissingIndicator columns. |
keep_empty_features | bool | False | Keyword-only; retain all-missing columns. |
device | str | None | None | Keyword-only; target compute device for default Ridge estimator. |
Methods & Fitted Attributes
- Methods:
fit(X, y=None),transform(X),fit_transform(X, y=None),save(path),load(path, device=None) - Attributes:
initial_imputer_,imputation_sequence_,indicator_,n_iter_,n_features_in_,n_features_with_missing_
Non-Linear, Feature & Kernel Transformers
Distribution transforms, discretization, polynomial/spline basis expansion, kernel centering, and Random Fourier Features in ochreml.preprocessing and ochreml.kernel_approximation.
Feature & Text Extraction
Rust-backed dictionary vectorization, MurmurHash3 feature hashing, and text tokenization/TF-IDF extraction in ochreml.feature_extraction.