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

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

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 float32 array. For partially observed training data, use donor_policy="available".

See usage examples for partial donors, missing indicators, custom markers, 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 either metric="l2" or metric="nan_euclidean". A donor must observe the target feature and share an observed feature with the query. If no usable neighbor 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; weights supported with mean and L2 metrics Weighted mean
Precision Converts inputs and outputs to float32 Supports floating inputs including float64
Metrics "l2", its "nan_euclidean" alias, and "ip" in complete mode "nan_euclidean" or a callable
Missing markers NaN or a finite numeric marker 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; float32 conversion, 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 either metric="l2" or metric="nan_euclidean".

See the API reference for accepted values, output rules, and edge cases.

Important behavior

  • Inputs must be two-dimensional numeric data. Observed values are converted to float32; infinity and values outside its finite range are rejected.
  • 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, eligible inputs may be modified even when added indicators cause a new output array to be returned.
  • 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: Hakkil Kim / 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.15

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.15
File Size Uploaded Provenance Actions
faiss_imputer-0.3.15.tar.gz 45.3 kB With provenance Details for faiss_imputer-0.3.15.tar.gz

Built distribution (wheel)

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

Total release size: 60.4 kB

Release files / faiss_imputer-0.3.15.tar.gz

Download URL faiss_imputer-0.3.15.tar.gz
Size 45.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fd02454caecb8f8c6db7374573a8b832b92ef1f46b05b68c54f1df9b3377ec1f
BLAKE2b-256 checksum
How to use checksums
85fb2d6fe9f84c65d3b9f7e5dd0538cf22d6c2cba2497d44260b830bce449e1b
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.15-py3-none-any.whl

Download URL faiss_imputer-0.3.15-py3-none-any.whl
Size 15.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a105fb26563f15f36f204a5dd0d82e6583f6d666a8faeb5d11f0cc227e0620f7
BLAKE2b-256 checksum
How to use checksums
a5870aa2f8d30ae50a0fd2fe5f3e273cad74a60fd829d4399f3114406d97bc72
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.15

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