ClusterImputer
A scikit-learn compatible Cluster-Aware Tabular Imputer for mixed numerical and categorical datasets, published in Nature Scientific Reports.
- Paper: Cluster-aware imputation: a hybrid XGBoost-based model for missing data
- Journal: Scientific Reports (Springer Nature), Volume 16, Article 70170 (2026)
- DOI: 10.1038/s41598-026-70170-9
Overview
ClusterImputer (also available as ClusteringImputer) addresses the limitation of traditional MICE global regression models by learning local correlation structures within tabular data:
- Missingness-Aware Chaining: Features are prioritized and imputed in ascending order of missingness (least missing to most missing).
- Subspace Clustering: For each feature, complete rows are projected into PCA space and partitioned using K-Means with automatic silhouette score optimization ($k$).
- Parallel Localized Ensembles: High-speed XGBoost regressors and classifiers are fitted per cluster in parallel.
- Iterative MICE Convergence: Chained updates repeat iteratively until numerical tolerance or maximum iterations are satisfied.
- Linear Computational Scaling: Benchmarked across 97 UCI datasets, demonstrating asymptotic linearity $\mathcal{O}(N)$ in computational complexity compared to KNN's quadratic $\mathcal{O}(N^2)$ scaling.
Installation
pip install cluster-imputer
Dependencies
numpy >= 1.20.0pandas >= 1.3.0scikit-learn >= 1.0.0xgboost >= 1.5.0joblib >= 1.1.0
Quick Start
import numpy as np
import pandas as pd
from cluster_imputer import ClusterImputer
# 1. Prepare sample data with missing entries
df = pd.DataFrame({
"feature_1": [1.2, np.nan, 3.4, 4.1, 5.0, 2.8, np.nan, 3.9],
"feature_2": [10.5, 20.1, np.nan, 40.2, 51.0, 22.3, 31.1, 41.5],
"category": ["A", "B", "A", np.nan, "B", "A", "B", np.nan],
})
# 2. Initialize the imputer
imputer = ClusterImputer(
n_clusters='auto', # Automatically finds optimal k via silhouette score
max_k=5,
max_iter=5,
n_jobs=-1
)
# 3. Fit and transform
df_imputed = imputer.fit_transform(df)
print(df_imputed)
Scikit-Learn Pipeline Integration
ClusterImputer inherits from BaseEstimator and TransformerMixin, making it seamlessly compatible with Pipeline, ColumnTransformer, and cross-validation:
from sklearn.pipeline import Pipeline
from sklearn.ensemble import RandomForestClassifier
from cluster_imputer import ClusterImputer
pipe = Pipeline([
("imputer", ClusterImputer(n_clusters=3, max_iter=5, n_jobs=-1)),
("classifier", RandomForestClassifier(n_estimators=100, random_state=42))
])
pipe.fit(X_train, y_train)
predictions = pipe.predict(X_test)
Hyperparameter Selection
To estimate recommended parameters based on dataset dimensionality and missingness ratio, use suggest_imputer_params:
from cluster_imputer import suggest_imputer_params
params = suggest_imputer_params(df)
print("Recommended parameters:", params)
imputer = ClusterImputer(**params)
df_clean = imputer.fit_transform(df)
Parameters and API Reference
ClusterImputer / ClusteringImputer
| Parameter | Type | Default | Description |
|---|---|---|---|
n_clusters |
'auto' or int |
'auto' |
Number of clusters. When 'auto', uses silhouette analysis. |
max_k |
int |
10 |
Maximum number of clusters evaluated when n_clusters='auto'. |
n_pca_components |
int |
4 |
Number of PCA dimensions for clustering. |
max_iter |
int |
10 |
Maximum outer chained MICE iterations. |
tol |
float |
1e-3 |
Convergence tolerance on squared change of numeric imputed values. |
n_jobs |
int |
-1 |
Number of CPU cores to use for parallel XGBoost training and silhouette computation. |
max_training_samples |
int or None |
10000 |
Subsampling limit to guarantee speed and memory safety on large datasets. |
Methods
fit(X, y=None): Learns clustering spaces and per-cluster XGBoost models on observed data.transform(X): Imputes missing values inXand returns a completed DataFrame or numpy ndarray.fit_transform(X, y=None): Fits and transforms the data in a single call.
Citation
If you use ClusterImputer in your research, please cite our article in Scientific Reports:
@article{ismail2026clusteraware,
title = {Cluster-aware imputation: a hybrid XGBoost-based model for missing data},
author = {Ismail, Mahmoud M. and Emad, Mohamed and Mohamed, Mai},
journal = {Scientific Reports},
volume = {16},
number = {1},
pages = {70170},
year = {2026},
publisher = {Springer Nature},
doi = {10.1038/s41598-026-70170-9},
url = {https://doi.org/10.1038/s41598-026-70170-9}
}
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for cluster-imputer 0.1.1
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 | |
|---|---|---|---|---|
| cluster_imputer-0.1.1.tar.gz | 15.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| cluster_imputer-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 27.3 kB
Release files / cluster_imputer-0.1.1.tar.gz
| Download URL | cluster_imputer-0.1.1.tar.gz |
|---|---|
| Size | 15.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
42e57088545b2d6b298831f1c8497f8742b6a9b79cd4a59199e040faba0a5fb8
|
|
BLAKE2b-256 checksum How to use checksums |
7c78a818aa1dc2801e96fb43eae10ff467483b3171a7f2c108e61e6540eed984
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Release files / cluster_imputer-0.1.1-py3-none-any.whl
| Download URL | cluster_imputer-0.1.1-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
6de76a37e984c8f91c09717bfa4a61513da79686d518abbeac7372cb17e04d36
|
|
BLAKE2b-256 checksum How to use checksums |
d0cde777b1aba34903b7052f6e99e005b4ca498d7add05412dbe186c91f8b74b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.9
|
Security for cluster-imputer 0.1.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.