Skip to main content

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

  1. Profile each target column (type, missingness, cardinality, distribution shape).
  2. Select features with mutual information (top 6 predictors by default).
  3. Route to a candidate model based on the column profile.
  4. Fit on observed rows, then impute missing cells column by column.
  5. 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
  • transform before fit raises RuntimeError

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

Imputation density comparison

Missingness heatmap before and after imputation

Per-column model allocation

Regenerate locally:

python scripts/generate_plots.py

Requirements

  • Python 3.10+
  • NumPy, Pandas, SciPy, scikit-learn, LightGBM, CatBoost

Contributing

  1. Fork Hvllvix/Simpute
  2. Create a branch, make changes, run pytest tests/guard.py -v
  3. Open a pull request

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

simpute-0.1.0.tar.gz (12.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

simpute-0.1.0-py3-none-any.whl (11.0 kB view details)

Uploaded Python 3

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

Hashes for simpute-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2d96f81a8e1a40cbec5c8e5629be44d6a1a5421017167eac4dd18ac5de4c3e6e
MD5 c6ff32e1c0b9dfa80665165e3be5e225
BLAKE2b-256 65072802945e361917cba0d28ecc885015e8cec86ea8101892f9cf7454ba98d0

See more details on using hashes here.

Provenance

The following attestation bundles were made for simpute-0.1.0.tar.gz:

Publisher: release.yml on Hvllvix/Simpute

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for simpute-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 78fc96b0a2c06fb738374050a41bc7b3ea2948d25a98248cdb9edf05f07917e8
MD5 563fc107499ee655590c14327f9f16ec
BLAKE2b-256 ae870bf7d166cff9b23042bd50f2cb6a45646f4bcee0b94d9d8b3c203131f18d

See more details on using hashes here.

Provenance

The following attestation bundles were made for simpute-0.1.0-py3-none-any.whl:

Publisher: release.yml on Hvllvix/Simpute

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page