Skip to main content

FaissImputer

Warning: FaissImputer 0.1.x has a known neighbor-mapping bug that can produce incorrect imputations, and it is incompatible with scikit-learn 1.8+. Use version 0.2.0 or newer.

PyPI Version License

Impute missing values using Meta's faiss - A Python library for missing data imputation with k nearest neighbors.

What's new in 0.2.1

Version 0.2.1 is a packaging and documentation hotfix. The imputation behavior is unchanged from 0.2.0.

  • Corrects the PyPI description so it no longer presents 0.2.0 as unreleased.
  • Uses portable warning markup and absolute documentation links that work on PyPI.
  • Verifies built package metadata against the release tag before publication.

See the 0.2.1 release notes for the packaged changes.

What's new in 0.2.0

Version 0.2.0 is the corrected release recommended for users upgrading from 0.1.x.

  • Corrects the neighbor-to-donor mapping that could return values from the wrong training row.
  • Uses the donor rows learned during fit() when new data is passed to transform().
  • Searches for neighbors using only the columns observed in each query row.
  • Preserves the input array and reuses fallback statistics learned during fit().
  • Supports modern scikit-learn validation APIs and adds regression tests and automatic CI.

Upgrade an existing installation with:

python -m pip install --upgrade "faiss-imputer>=0.2.1"

See the 0.2.0 release notes and the full benchmark report for details and current limitations.

Installation

You can install faiss-imputer using pip:

FaissImputer requires Python 3.10 or newer.

pip install faiss-imputer

Usage

import numpy as np

from faiss_imputer import FaissImputer

# Complete rows used as reference donors
X_train = np.array(
    [
        [1.0, 10.0, 100.0],
        [2.0, 20.0, 200.0],
        [3.0, 30.0, 300.0],
    ],
    dtype=np.float32,
)

# New rows containing missing values
X_missing = np.array(
    [
        [1.5, np.nan, 150.0],
        [2.5, 25.0, np.nan],
    ],
    dtype=np.float32,
)

imputer = FaissImputer(n_neighbors=2)
imputer.fit(X_train)

X_imputed = imputer.transform(X_missing)
print(X_imputed)

transform() returns a NumPy float32 array. The input array is not modified.

Parameters

  • n_neighbors: Number of reference rows used to calculate each missing value.
  • metric: Neighbor-search metric. Supported values are "l2" and "ip". Raw inner product is not cosine similarity.
  • strategy: Aggregation method for neighbor values. Supported values are "mean" and "median".
  • index_factory: Faiss index description. The default "Flat" performs exact search.

Important behavior

  • fit() currently uses only rows without any missing values as reference donors.
  • Neighbor search compares only the columns observed in each query row.
  • n_neighbors cannot exceed the number of complete reference rows.
  • An entirely missing row is filled using statistics learned during fit().
  • Input data must be a two-dimensional numeric array with the same number of columns used during fit().

Benchmark

In a controlled synthetic benchmark with complete training donors, FaissImputer 0.2.0 and scikit-learn's KNNImputer produced exactly matching imputed values. With 20,000 training rows, FaissImputer transformed repeated missingness patterns up to 19.62 times faster, while performance was effectively tied when almost every test row had a different pattern.

When the training data itself contained missing values, FaissImputer was less accurate because version 0.2.0 uses only fully observed rows as donors. These single-thread results are specific to the tested synthetic data and hardware, not a general performance guarantee.

See the full 0.2.0 benchmark report, reproduction script, and raw results. Planned improvements are tracked in the roadmap.

Example notebook

See Imputing Missing Values with Faiss Imputer for a notebook example.

Contributing

Contributions are welcome! If you find a bug or have an enhancement suggestion, please open an issue or create a pull request.

Author

License

This project is licensed under the MIT License.

Third-Party Licenses

FaissImputer depends on Meta's Faiss, which is distributed under the MIT License.

FaissImputer is not affiliated with or endorsed by Meta or the Faiss maintainers.

For detailed licensing information of the Faiss library, please refer to the Faiss repository.

Metadata

Release files for faiss-imputer 0.2.1

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.2.1
File Size Uploaded Provenance Actions
faiss_imputer-0.2.1.tar.gz 7.1 kB With provenance Details for faiss_imputer-0.2.1.tar.gz

Built distribution (wheel)

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

Total release size: 13.6 kB

Release files / faiss_imputer-0.2.1.tar.gz

Download URL faiss_imputer-0.2.1.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
df24763296b09b3fdd3761efae94a573aae2228d9efbdc2b95bafc969500794b
BLAKE2b-256 checksum
How to use checksums
620f0886cb670fb92454ea53d56abf15e68dded346fe9923aa582c2b7fe40a47
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 2, 2026.

Transparency log

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

Download URL faiss_imputer-0.2.1-py3-none-any.whl
Size 6.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5bc5353de451a82fe46a5490917a5f5133af7dd00db57b942080449e1d44988f
BLAKE2b-256 checksum
How to use checksums
1a55023568cd26e2e00da36923594d2b9bef08ed923b18c0c022b37894bfac29
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 2, 2026.

Transparency log

Security for faiss-imputer 0.2.1

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.2.1.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 2, 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.2.1 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