Skip to main content

PAIN-Imputer: Precision Adaptive Imputation for Mixed-Type Data

PyPI version License: MIT Python 3.8+ Build Status

pain-imputer is a Python package built around the values and research-backed Precision Adaptive Imputation Network (PAIN) a tri-step imputation framework designed to handle datasets containing both numerical and categorical features with varying missingness patterns.


Table of Contents


What is PAIN?

PAIN Imputer is a state-of-the-art missing data imputation library that combines statistical methods, machine learning, and neural networks in a tri-step architecture. It is a research-based architecture, proposed in [PAIN paper on arXiv] (https://arxiv.org/abs/2501.10667) consistently outperforms traditional imputation methods while preserving data distributions and relationships.

Unlike traditional imputers that rely on statistical or machine learning methods, PAIN-Imputer combines three complementary strategies:

  1. Statistical Imputation
  2. Machine Learning-based Estimation
  3. Neural Autoencoder with Iterative Refinement

Note: This is a beta release; expect updates as we continue to refine the library.

Key Features

  • Handles both categorical and numerical data
  • Tri-step imputation strategy for high accuracy and stability
  • Works well with high-dimensional datasets
  • Automatically detects data types and missingness patterns
  • Research-validated on real-world benchmark datasets
  • Easy to integrate into any ML pipeline

Installation

  • Install from PyPI:
pip install pain-imputer

Or

  • Install from source:
git clone https://github.com/RajEshwariCodes/PAIN_Library.git
cd pain-imputer
pip install -e .

Requirements

  • Python ≥ 3.7
  • numpy
  • pandas
  • scikit-learn
  • tensorflow

Quickstart

import pandas as pd
import numpy as np
from pain_imputer import PAINImputer

# Load your data with missing values
data = pd.read_csv('your_dataset.csv')

# Initialize PAIN Imputer
imputer = PAINImputer(
    n_iterations=5,
    n_neighbors=5,
    random_state=42
)

# Transform incomplete data to complete
imputed_data = imputer.fit_transform(data)

print(f"Missing values before: {data.isnull().sum().sum()}")
print(f"Missing values after: {imputed_data.isnull().sum().sum()}")

Real-World Example: Forest Fire Data

import pandas as pd
from pain_imputer import PAINImputer

#Load forest fire dataset with missing values
df = pd.read_csv('forestfires.csv')

#Create PAIN imputer with custom settings
imputer = PAINImputer(
    n_iterations=3,          # Number of refinement iterations
    n_neighbors=7,           # KNN neighbors for baseline
    n_estimators=150,        # Random Forest trees
    encoder_layers=[128, 64, 32],  # Autoencoder architecture
    random_state=42
)

#Impute missing values
complete_data = imputer.fit_transform(df)

#Verify data integrity
print("Original data shape:", df.shape)
print("Imputed data shape:", complete_data.shape)
print("Data types preserved:", (df.dtypes == complete_data.dtypes).all())

API Reference

PAINImputer Class
class PAINImputer:
    def __init__(
        self,
        n_iterations: int = 5,
        n_neighbors: int = 5,
        n_estimators: int = 100,
        encoder_layers: List[int] = [64, 32, 16],
        random_state: int = 42
    )

Parameters

Parameter Type Default Description
n_iterations int 5 Number of refinement iterations in Layer 2
n_neighbors int 5 Number of neighbors for KNN imputation
n_estimators int 100 Number of trees in Random Forest
encoder_layers List[int] [64, 32, 16] Hidden layer sizes for autoencoder
random_state int 42 Random seed for reproducibility

Running Tests

To run the test suite and verify the library’s functionality, use pytest. First, ensure you have pytest installed:

pip install pytest

Then, run the tests:

pytest tests/

This will execute all unit tests in the tests/ directory, helping contributors ensure their changes don’t break existing functionality.


How It Works

(Tri-Step Pipeline)

  • Baseline Imputation
    Uses mean/median/KNN weighted by missingness ratio.
  • Advanced Modeling
    Uses random forests and autoencoders to refine imputations iteratively.
  • Refinement Clips imputed values to avoid outliers, preserving statistical consistency.

Use Cases

  • Medical datasets with missing physiological values
  • Mixed survey data (text + numbers)
  • High-dimensional research datasets
  • ML preprocessing pipelines
  • Any situation where missing values exist in structured data

Contributing

We welcome contributions ! Whether it’s a bug fix, feature request, or new idea, submit pull requests via our GitHub repository.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Maintainer: Rajeshwari Mistri Email: [rajeshwarimistri11@gmail.com] (mailto:rajeshwarimistri11@gmail.com) Project Repository: GitHub

Ready to make missing data painless? pip install pain-imputer and transform your incomplete datasets today!

Metadata

Release files for pain-imputer 0.1.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pain-imputer 0.1.3
File Size Uploaded Provenance Actions
pain_imputer-0.1.3.tar.gz 6.9 kB With provenance Details for pain_imputer-0.1.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pain-imputer 0.1.3
File Interpreter ABI Platform Actions
pain_imputer-0.1.3-py3-none-any.whl Python 3 none any Details for pain_imputer-0.1.3-py3-none-any.whl

Total release size: 14.2 kB

Release files / pain_imputer-0.1.3.tar.gz

Download URL pain_imputer-0.1.3.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bc8e29663cf575cbb9152aecac485a1d259635fc92185778e4ec90ea69e0fb83
BLAKE2b-256 checksum
How to use checksums
2929cf9f2e1b7e4595b65b4213609d1c1c911c2582199babb89f903d1e82098f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jun 2, 2025.

Transparency log

Release files / pain_imputer-0.1.3-py3-none-any.whl

Download URL pain_imputer-0.1.3-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
926a8ca9191d9da83b8ceae925e5e3c3680a2c9b9ca59c806b228f717b23e65b
BLAKE2b-256 checksum
How to use checksums
7dd4b6e9f79fc5fbaf3bd8ea6edb4def7d00eb1eb8d9c72c884d83bfe3027f07
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.12.9

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 Jun 2, 2025.

Transparency log

Security for pain-imputer 0.1.3

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 pain_imputer-0.1.3.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 Jun 2, 2025.

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.

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