PAIN : A library for imputing missing values
Project description
PAIN-Imputer: Precision Adaptive Imputation for Mixed-Type Data
pain-imputeris 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?
- Key Features
- Installation
- Quickstart
- API Reference
- How It Works
- Use Cases
- Running Tests
- Contributing
- License
- Contact
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:
- Statistical Imputation
- Machine Learning-based Estimation
- 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!
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
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 pain_imputer-0.1.3.tar.gz.
File metadata
- Download URL: pain_imputer-0.1.3.tar.gz
- Upload date:
- Size: 6.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bc8e29663cf575cbb9152aecac485a1d259635fc92185778e4ec90ea69e0fb83
|
|
| MD5 |
18b49597ac0b6d16cd5ba3ad65059699
|
|
| BLAKE2b-256 |
2929cf9f2e1b7e4595b65b4213609d1c1c911c2582199babb89f903d1e82098f
|
Provenance
The following attestation bundles were made for pain_imputer-0.1.3.tar.gz:
Publisher:
publish.yml on RajEshwariCodes/PAIN_Library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pain_imputer-0.1.3.tar.gz -
Subject digest:
bc8e29663cf575cbb9152aecac485a1d259635fc92185778e4ec90ea69e0fb83 - Sigstore transparency entry: 227047004
- Sigstore integration time:
-
Permalink:
RajEshwariCodes/PAIN_Library@3cc2c488f0d7b96debe6ee2d9e94588b7aaa56c9 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/RajEshwariCodes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3cc2c488f0d7b96debe6ee2d9e94588b7aaa56c9 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pain_imputer-0.1.3-py3-none-any.whl.
File metadata
- Download URL: pain_imputer-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
926a8ca9191d9da83b8ceae925e5e3c3680a2c9b9ca59c806b228f717b23e65b
|
|
| MD5 |
c28199d5116b7c7bb7d58051b4968dda
|
|
| BLAKE2b-256 |
7dd4b6e9f79fc5fbaf3bd8ea6edb4def7d00eb1eb8d9c72c884d83bfe3027f07
|
Provenance
The following attestation bundles were made for pain_imputer-0.1.3-py3-none-any.whl:
Publisher:
publish.yml on RajEshwariCodes/PAIN_Library
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pain_imputer-0.1.3-py3-none-any.whl -
Subject digest:
926a8ca9191d9da83b8ceae925e5e3c3680a2c9b9ca59c806b228f717b23e65b - Sigstore transparency entry: 227047006
- Sigstore integration time:
-
Permalink:
RajEshwariCodes/PAIN_Library@3cc2c488f0d7b96debe6ee2d9e94588b7aaa56c9 -
Branch / Tag:
refs/tags/v0.1.3 - Owner: https://github.com/RajEshwariCodes
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@3cc2c488f0d7b96debe6ee2d9e94588b7aaa56c9 -
Trigger Event:
release
-
Statement type: