FaissImputer
Nearest-neighbor imputation with Faiss-backed search, scikit-learn pipelines, feature names, and optional pandas output.
Current release: 0.3.19.
FaissImputer 0.1.x has a known neighbor-mapping bug and is incompatible with scikit-learn 1.8+. Use version 0.2.0 or newer.
Installation
Requires Python 3.10 or newer.
python -m pip install --upgrade "faiss-imputer>=0.3.19"
Quick start
import numpy as np
from faiss_imputer import FaissImputer
train = np.array([[0, 10], [2, 20], [4, 40]], dtype=np.float32)
query = np.array([[1.8, np.nan]], dtype=np.float32)
imputer = FaissImputer(n_neighbors=1)
print(imputer.fit(train).transform(query))
# [[ 1.8 20. ]]
By default, inputs are preserved and output is a NumPy array.
Query arrays retain their float32 or float64 dtype.
For partially observed training data, use donor_policy="available".
See usage examples for partial donors, missing indicators, custom markers, callable metrics, and pandas pipelines.
Choosing a donor policy
| Policy | Training data and donor selection |
|---|---|
"complete" (default) |
Uses rows observed in every non-empty training column. Requires at least n_neighbors such rows when non-empty columns exist. |
"available" |
Allows partially observed rows. Selects eligible donors separately for each missing feature and permits fewer than n_neighbors usable donors. |
Available mode requires index_factory="Flat" and metric="l2",
metric="nan_euclidean", or a callable. Donors must observe the target
feature and have a defined distance to the query. Built-in L2 metrics
require a shared observed feature. If no usable donor exists, the fitted
column statistic supplies the value.
Comparison with KNNImputer
The comparison below describes FaissImputer 0.3.15.
| Behavior | FaissImputer | KNNImputer |
|---|---|---|
| Defaults | 3 neighbors, complete donors | 5 neighbors, donors selected per feature |
| Aggregation | Mean or median; non-uniform weights with mean and L2 or callable metrics | Weighted mean |
| Precision | Preserves float32 and float64 values; complete-donor search with built-in metrics uses float32 vectors |
Supports floating inputs including float64 |
| Metrics | "l2", its "nan_euclidean" alias, "ip" in complete mode, and callables under both donor policies |
"nan_euclidean" or a callable |
| Missing markers | NaN or a finite numeric marker, matched before dtype conversion |
Configurable missing_values |
Both provide missing indicators, empty-feature retention, and a copy option.
Their detailed input and copying rules can differ.
For a closer comparison, use donor_policy="available",
metric="nan_euclidean", and matching neighbor counts, weights, and missing
markers. Matching settings does not guarantee identical donor choices or
imputed values; search precision, distance calculations, and ties matter.
Parameters
Parameter names and defaults
| Parameter | Default |
|---|---|
n_neighbors |
3 |
metric |
"l2" |
strategy |
"mean" |
index_factory |
"Flat" |
donor_policy |
"complete" |
weights |
"uniform" |
add_indicator |
False |
keep_empty_features |
False |
missing_values |
np.nan |
copy |
True |
Distance and callable weights require strategy="mean" and
metric="l2", metric="nan_euclidean", or a callable metric.
Callable metrics require index_factory="Flat" and evaluate donors
directly in Python, which can be slower than built-in metrics.
See the API reference for accepted values, output rules, and edge cases.
Important behavior
- Inputs must be two-dimensional numeric data.
float32andfloat64arrays retain their dtype; integer arrays are converted tofloat32. Observed values must be finite. Output dtype follows the query after input conversion. - Columns entirely missing during fit are dropped by default.
keep_empty_features=Trueretains them with zero values, including when later queries contain observed values in those columns. transform()requires the original input feature count. Indicator columns are selected during fit and remain fixed until refitting.copy=Truepreserves inputs. Withcopy=False, writable contiguousfloat32orfloat64input may be modified, even when indicators or output formatting create a new returned object.- Entirely missing query rows use fitted column means or medians. A failed fit or refit clears the fitted state.
Benchmarks
The following historical measurements compare PyPI FaissImputer 0.3.10 with KNNImputer from scikit-learn 1.9.0.
The AMD runner used one thread, 20,000 training rows, 300 queries, 20 features, five neighbors, and uniform-weight mean aggregation. Each query had four missing features. Complete-mode training data was fully observed; available-mode training data had approximately 10% MCAR missingness.
Times are first-transform medians across three seeds and three fresh runs per seed, excluding fit time.
| Donor policy | Query missingness | KNNImputer | FaissImputer | Speedup |
|---|---|---|---|---|
| complete | One shared pattern | 422.4 ms | 22.0 ms | 19.24× |
| complete | Random patterns | 409.8 ms | 107.2 ms | 3.82× |
| available | One shared pattern | 391.4 ms | 166.2 ms | 2.35× |
| available | Random patterns | 385.6 ms | 167.5 ms | 2.30× |
Performance varies with workload. A separate Intel training-size sweep included a slower case: complete mode with random query patterns at 1,000 training rows achieved 0.71× KNNImputer's speed. Memory advantages also varied with data size.
These measurements apply to 0.3.10 and the recorded hardware and workloads. See the benchmark reports for detailed conditions, quality comparisons, and historical experiments.
Documentation
Contributing
Bug reports and pull requests are welcome. Please use the issue tracker.
Author: ScionKim.
License
This project is licensed under the MIT License.
Faiss is developed by Meta and distributed under the MIT License. FaissImputer is not affiliated with or endorsed by Meta or the Faiss maintainers.
Metadata
Release files for faiss-imputer 0.3.19
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| faiss_imputer-0.3.19.tar.gz | 51.2 kB | With provenance | Details for faiss_imputer-0.3.19.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| faiss_imputer-0.3.19-py3-none-any.whl | Python 3 | none | any | Details for faiss_imputer-0.3.19-py3-none-any.whl |
Total release size: 68.0 kB
Release files / faiss_imputer-0.3.19.tar.gz
| Download URL | faiss_imputer-0.3.19.tar.gz |
|---|---|
| Size | 51.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bc1f1b353543d582c6d51fc6ac4bc713bec3cfcdd43371f864482139a28a37af
|
|
BLAKE2b-256 checksum How to use checksums |
1aeb113c415375fc97051d4e4fad8f334b77b87bbefe0cbccf4e2bb9e3c9fa41
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logRelease files / faiss_imputer-0.3.19-py3-none-any.whl
| Download URL | faiss_imputer-0.3.19-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
f4acb8983063ca07301e55c2fcb973f43943989bfa9c3f616474b77abdbde244
|
|
BLAKE2b-256 checksum How to use checksums |
6837252d6fe6647a3ae03dcb55f7ad90c50c276d9f12c980ddc70ee840546850
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logSecurity for faiss-imputer 0.3.19
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for faiss_imputer-0.3.19.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Sep 13, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.