Skip to main content

FaissImputer

PyPI Version License

Nearest-neighbor imputation with Faiss-backed search, scikit-learn pipelines, feature names, and optional pandas output.

Current release: 0.3.17.

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.17"

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. float32 and float64 arrays retain their dtype; integer arrays are converted to float32. 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=True retains 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=True preserves inputs. With copy=False, writable contiguous float32 or float64 input 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×

AMD results and environment

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.

Intel results and environment

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.17

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for faiss-imputer 0.3.17
File Size Uploaded Provenance Actions
faiss_imputer-0.3.17.tar.gz 51.2 kB With provenance Details for faiss_imputer-0.3.17.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for faiss-imputer 0.3.17
File Interpreter ABI Platform Actions
faiss_imputer-0.3.17-py3-none-any.whl Python 3 none any Details for faiss_imputer-0.3.17-py3-none-any.whl

Total release size: 68.0 kB

Release files / faiss_imputer-0.3.17.tar.gz

Download URL faiss_imputer-0.3.17.tar.gz
Size 51.2 kB
Tags Source
SHA-256 checksum
How to use checksums
3417d28eab1fb6424f91ad2bc0f2858fc1738bbc165333a2d89611fcc08800a9
BLAKE2b-256 checksum
How to use checksums
c10f570e225c086b427e130e8998e9225ffc87b6e21fb4a1f92229d239d7738b
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 log

Release files / faiss_imputer-0.3.17-py3-none-any.whl

Download URL faiss_imputer-0.3.17-py3-none-any.whl
Size 16.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
99f338aeb2534f972f773b3aef9d9b4417944c7a637e76f22501b4cf6d29c5ce
BLAKE2b-256 checksum
How to use checksums
f06435c0a0907e00881812247684b4884310c101bdb54e7c9ebeb9a72a3d6f2b
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 log

Security for faiss-imputer 0.3.17

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.

Select from 2 files

Attestation for faiss_imputer-0.3.17.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 log

A 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.

Release history Release notifications | RSS feed

This release

0.3.17 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page