imputation-methods
42 missing-data imputation methods behind one pandas API. Swap mean imputation for KNN, MICE, a Kalman filter or low-rank matrix completion by changing one line, and compare them with the same evaluation code.
from imputation_methods import KNNImputerMethod
completed = KNNImputerMethod(k=5).impute(df)
- One interface. Every imputer takes a numeric
DataFrameand returns a new one with the same index and columns. The input is never modified. - Broad coverage. Statistical, donor-based, time-series, nearest-neighbor, regression, iterative, matrix-completion, neural and ensemble methods.
- Light dependencies. NumPy, pandas, SciPy and scikit-learn only.
- Typed and tested. Inline type hints checked by mypy in strict mode, and tests on Python 3.10–3.14, on the newest and the oldest supported dependency versions.
Installation
pip install imputation-methods
The optional viz extra installs matplotlib and seaborn, used by the example
notebooks and scripts:
pip install "imputation-methods[viz]"
Requires Python 3.10 or newer.
Quick start
import numpy as np
import pandas as pd
from imputation_methods import KNNImputerMethod, MeanImputer, knn_impute
df = pd.DataFrame(
{
"height": [170.0, 165.0, np.nan, 180.0, 175.0],
"weight": [65.0, np.nan, 70.0, 85.0, 78.0],
"age": [30.0, 25.0, 35.0, np.nan, 40.0],
}
)
mean_filled = MeanImputer().impute(df)
knn_filled = KNNImputerMethod(k=2).impute(df)
# Every imputer also has a functional shortcut.
same_as_knn = knn_impute(df, k=2)
Imputers are configured in the constructor. Those with a random component accept
random_state for reproducible results.
Available methods
| Family | Imputers |
|---|---|
| Statistical | MeanImputer, MedianImputer, ModeImputer, ConstantImputer, QuantileImputer, TrimmedMeanImputer, EndOfDistributionImputer, GroupMeanImputer, IndicatorImputer |
| Donor sampling | RandomSamplingImputer, HotDeckImputer, ColdDeckImputer |
| Time series | LOCFImputer, NOCBImputer, ForwardFillFallbackImputer, InterpolationImputer, MovingAverageImputer, WeightedMovingAverageImputer, LinearTrendImputer, PolynomialTrendImputer, SeasonalImputer, KalmanFilterImputer |
| Nearest neighbors | KNNImputerMethod, RadiusNeighborsImputer, LocalMeanImputer |
| Regression | RegressionImputer, StochasticRegressionImputer, PMMImputer (predictive mean matching), BayesianRidgeImputer, HuberImputer, RANSACImputer, GaussianProcessImputer |
| Iterative | MICEImputer, MissForestImputer, EMImputer |
| Matrix completion | SoftImputeImputer, BayesianPCAImputer (probabilistic PCA) |
| Neural networks | AutoencoderImputer, GAINImputer (generative adversarial imputation) |
| Ensembles | HybridImputer (fallback chain), StackingImputer, BaggingImputer (bootstrap aggregating) |
EMImputer runs iterative chained-equation imputation rather than closed-form EM
for a multivariate normal distribution.
The API reference documents every class and its parameters.
Evaluating an imputation
When you have complete data, hide some values, impute them, and score only the cells you hid:
import numpy as np
import pandas as pd
from sklearn.datasets import load_diabetes
from imputation_methods import KNNImputerMethod, MeanImputer, MICEImputer, mae, rmse
complete = load_diabetes(as_frame=True).data
rng = np.random.default_rng(0)
mask = rng.random(complete.shape) < 0.2
incomplete = complete.mask(mask)
imputers = {
"mean": MeanImputer(),
"knn": KNNImputerMethod(k=5),
"mice": MICEImputer(random_state=0),
}
for name, imputer in imputers.items():
completed = imputer.impute(incomplete)
true = pd.Series(complete.to_numpy()[mask])
pred = pd.Series(completed.to_numpy()[mask])
print(f"{name:>5}: RMSE={rmse(true, pred):.4f} MAE={mae(true, pred):.4f}")
Input requirements
- A
pandas.DataFramewith numeric columns; missing values asNaN(orpd.NAin nullable dtypes). Encode categorical columns before imputing.GroupMeanImputeris the exception: its grouping column may be non-numeric. - Time-series imputers use row order, so sort the data first.
- Columns with no observed values are left as
NaNby most imputers.
Documentation
Full documentation, including guides on choosing a method and evaluating results: https://diogoribeiro7.github.io/imputation-methods/
The repository also has example scripts and Jupyter notebooks.
Contributing
Contributions are welcome. See the contributing guide for the development setup, and the code of conduct. Report security issues as described in the security policy.
Citation
If you use this library in research, please cite it. Citation metadata is in
CITATION.cff;
GitHub's "Cite this repository" button exports it as BibTeX or APA.
License
MIT. See LICENSE.
Release files for imputation-methods 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| imputation_methods-0.1.0.tar.gz | 58.0 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| imputation_methods-0.1.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size:105.0 kB
Release files / imputation_methods-0.1.0.tar.gz
| Download URL | imputation_methods-0.1.0.tar.gz |
|---|---|
| Size | 58.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9f733f4bffa1bc2e30770f2df4ddb2b6c4fa5356f8dc6f436d4fb902884df36
|
|
BLAKE2b-256 checksum How to use checksums |
57805bde21eacceec9d89005d64b320d7017b88164c5f2e6adb1c6a152ed87ad
|
| 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 16, 2026.
Transparency logRelease files / imputation_methods-0.1.0-py3-none-any.whl
| Download URL | imputation_methods-0.1.0-py3-none-any.whl |
|---|---|
| Size | 47.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
46a83bc632c571d7b81e6946ebaa5cc28109fcbe16fe7858ba734926b2bb2a2d
|
|
BLAKE2b-256 checksum How to use checksums |
7cd08e7c08cb973263f8ac642e1a7ef40a2bc87a6a198b61731eb23ccd59f9b9
|
| 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 16, 2026.
Transparency log