Smart Impute: adaptive per-column missing value imputation
Project description
Simple Imputation
Simpute (simple + impute) is an adaptive missing-value imputation library for tabular data. Instead of applying one global strategy to every column, it profiles each feature, selects a tailored model, and imputes columns sequentially so earlier fills inform later ones.
Install from PyPI as simpute. Source and releases live at github.com/Hvllvix/Simpute.
Why Simpute
Most imputers pick a single method (mean, median, MICE, KNN) for the whole table. Real datasets mix binary flags, low-cardinality categories, high-cardinality text-like fields, skewed counts, and smooth continuous variables. Simpute treats each column on its own terms.
| Approach | Simpute |
|---|---|
| Strategy | Per-column profiling and model routing |
| API | Scikit-learn fit / transform / fit_transform |
| Models | LightGBM, CatBoost, logistic/SVM, KNN, Bayesian Ridge, Extra Trees |
| Safety | Guard test suite with ground-truth verification |
| Warnings | Flags columns above 70% missingness |
Installation
pip install simpute
Development install with tests and plotting extras:
git clone https://github.com/Hvllvix/Simpute.git
cd Simpute
pip install -e ".[dev]"
Quick Start
import pandas as pd
from simpute import Simpute
df = pd.read_csv("data.csv")
imputer = Simpute(exclude=["Student_ID"])
filled = imputer.fit_transform(df)
print(imputer.getmodelselection())
print(imputer.getprofiles())
exclude keeps identifier columns out of the imputation loop. Use columns=[...] instead when you only want to impute a subset.
How It Works
- Profile each target column (type, missingness, cardinality, distribution shape).
- Select features with mutual information (top 6 predictors by default).
- Route to a candidate model based on the column profile.
- Fit on observed rows, then impute missing cells column by column.
- Warn when missingness exceeds 70% on a column.
Sequential imputation means numerical columns are generally filled before categorical ones, and values imputed in earlier columns become features for later columns.
Model Selection
| Column profile | Candidate models |
|---|---|
| High-cardinality categorical | CatBoost Classifier, LightGBM Classifier |
| Low-cardinality / binary categorical | Logistic Regression, Linear SVC |
| Large numerical tables (1000+ rows) | LightGBM Regressor, Extra Trees Regressor |
| Skewed or discrete numerical | LightGBM Regressor, Extra Trees Regressor |
| Normal / uniform continuous | KNN Regressor, Bayesian Ridge |
Inspect the chosen backend per column after fitting:
imputer.getmodelselection()
# {'Pre_Semester_GPA': 'LGBMRegressor', 'Major_Category': 'CatBoostClassifier', ...}
API Reference
| Method | Description |
|---|---|
fit(df) |
Profile columns, train per-column models |
transform(df) |
Impute using fitted models |
fit_transform(df) |
Fit and impute in one pass (recommended) |
getprofiles() |
Column profiles used during routing |
getmodelselection() |
Model name chosen for each imputed column |
Constructor options: columns, exclude, maskratio, randomstate.
Guard Tests
The guard suite (tests/guard.py) masks values in tests/data/test.csv, imputes them, and checks:
- No NaN values remain after imputation
- Categorical predictions stay within the original domain
- Numerical predictions stay within bounded ranges
- Imputation beats adaptive random baselines on held-out masked cells
- Model selection is deterministic and profile-consistent
- High-missingness columns emit warnings
transformbeforefitraisesRuntimeError
See tests/data/README.md for column descriptions and how to swap in your own CSV.
pytest tests/guard.py -v
Metric summary table (MAE for continuous columns, accuracy for nominal):
python tests/guard.py
Validation Plots
Generated on the bundled test dataset (MASKRATIO=0.15, SEED=42):
| Plot | Description |
|---|---|
| Imputation density | KDE of observed vs post-imputation continuous distributions |
| Missingness heatmap | Feature completeness before and after imputation |
| Model allocation | Which backend was assigned per column |
Regenerate locally:
python scripts/generate_plots.py
Requirements
- Python 3.10+
- NumPy, Pandas, SciPy, scikit-learn, LightGBM, CatBoost
Contributing
- Fork Hvllvix/Simpute
- Create a branch, make changes, run
pytest tests/guard.py -v - Open a pull request
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file simpute-0.1.0.tar.gz.
File metadata
- Download URL: simpute-0.1.0.tar.gz
- Upload date:
- Size: 12.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2d96f81a8e1a40cbec5c8e5629be44d6a1a5421017167eac4dd18ac5de4c3e6e
|
|
| MD5 |
c6ff32e1c0b9dfa80665165e3be5e225
|
|
| BLAKE2b-256 |
65072802945e361917cba0d28ecc885015e8cec86ea8101892f9cf7454ba98d0
|
Provenance
The following attestation bundles were made for simpute-0.1.0.tar.gz:
Publisher:
release.yml on Hvllvix/Simpute
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simpute-0.1.0.tar.gz -
Subject digest:
2d96f81a8e1a40cbec5c8e5629be44d6a1a5421017167eac4dd18ac5de4c3e6e - Sigstore transparency entry: 1933888369
- Sigstore integration time:
-
Permalink:
Hvllvix/Simpute@c96c65abf6e981b980bcb66dd4a170302bb4ded9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Hvllvix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c96c65abf6e981b980bcb66dd4a170302bb4ded9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file simpute-0.1.0-py3-none-any.whl.
File metadata
- Download URL: simpute-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
78fc96b0a2c06fb738374050a41bc7b3ea2948d25a98248cdb9edf05f07917e8
|
|
| MD5 |
563fc107499ee655590c14327f9f16ec
|
|
| BLAKE2b-256 |
ae870bf7d166cff9b23042bd50f2cb6a45646f4bcee0b94d9d8b3c203131f18d
|
Provenance
The following attestation bundles were made for simpute-0.1.0-py3-none-any.whl:
Publisher:
release.yml on Hvllvix/Simpute
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
simpute-0.1.0-py3-none-any.whl -
Subject digest:
78fc96b0a2c06fb738374050a41bc7b3ea2948d25a98248cdb9edf05f07917e8 - Sigstore transparency entry: 1933888464
- Sigstore integration time:
-
Permalink:
Hvllvix/Simpute@c96c65abf6e981b980bcb66dd4a170302bb4ded9 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/Hvllvix
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@c96c65abf6e981b980bcb66dd4a170302bb4ded9 -
Trigger Event:
release
-
Statement type: