Skip to content

Imputation Methods

PyPI Python versions CI License: MIT Ruff

A unified pandas API for 42 missing-data imputation methods: statistical, time-series, regression, ensemble and matrix-completion.


Overview

Missing data is a common challenge in data science and machine learning. imputation-methods provides a unified interface for comparing and evaluating different imputation strategies, from simple statistical methods to advanced machine learning approaches.

Features

โœจ 42 Imputation Methods - From mean/median to MICE, MissForest and SoftImpute

๐ŸŽฏ Unified API - Every imputer exposes impute(df), and each has a functional shortcut such as mean_impute(df)

๐Ÿ”’ Type-Safe - Full type hints (ships py.typed), checked with mypy in strict mode

๐Ÿ“Š Evaluation Metrics - RMSE, MAE for quality assessment

๐Ÿงช Well-Tested - Test suite and doctests run in CI on Python 3.10โ€“3.14

๐Ÿ“š Extensive Documentation - Tutorials, examples, and API docs

Quick Example

import pandas as pd
import numpy as np
from imputation_methods import KNNImputer

# Create data with missing values
df = pd.DataFrame({
    'feature1': [1.0, 2.0, np.nan, 4.0, 5.0],
    'feature2': [5.0, np.nan, np.nan, 8.0, 10.0],
})

# Apply KNN imputation
imputer = KNNImputer(n_neighbors=3)
df_imputed = imputer.impute(df)

print(df_imputed)

Available Methods

Statistical Methods

  • Mean, Median, Mode Imputation
  • Constant, Quantile and Trimmed Mean Imputation
  • End-of-Distribution Imputation
  • Group Mean/Median Imputation
  • Missing Indicator + Imputation

Sampling Methods

  • Random Sampling
  • Hot Deck
  • Cold Deck

Time Series Methods

  • LOCF (Last Observation Carried Forward)
  • NOCB (Next Observation Carried Backward)
  • Forward Fill with Mean/Median Fallback
  • Interpolation (linear, polynomial, spline)
  • Moving Average and Exponentially Weighted Moving Average
  • Linear and Polynomial Trend
  • Seasonal Imputation
  • Kalman Filter

Distance-Based Methods

  • K-Nearest Neighbors
  • Radius Neighbors
  • Local Weighted Mean

Regression-Based Methods

  • Linear Regression
  • Stochastic Regression
  • Predictive Mean Matching (PMM)
  • Bayesian Ridge
  • Huber and RANSAC Robust Regression
  • Gaussian Process

Iterative Methods

  • MICE (Multiple Imputation by Chained Equations)
  • MissForest
  • EM-style iterative imputation (chained equations, not closed-form multivariate-normal EM)

Matrix Completion Methods

  • SoftImpute
  • Bayesian PCA (maximum-likelihood probabilistic PCA)

Neural Network Methods

  • Autoencoder
  • GAIN (Generative Adversarial Imputation Nets)

Ensemble Methods

  • Hybrid (fallback chain)
  • Stacking (mean/median of several imputers)
  • Bagging (bootstrap aggregating of a base imputer)

Installation

pip install imputation-methods

# With the optional plotting dependencies (matplotlib, seaborn)
pip install "imputation-methods[viz]"
poetry add imputation-methods
git clone https://github.com/DiogoRibeiro7/imputation-methods.git
cd imputation-methods
poetry install

Next Steps

  • Getting Started


    Learn the basics with our comprehensive tutorial

    Quick Start

  • User Guide


    Explore the imputation methods and when to use them

    Methods Overview

  • Examples


    See practical examples for real-world scenarios

    View Examples

  • API Reference


    Detailed API documentation for all methods

    API Docs

Community

License

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

Citation

If you use this library in your research:

@software{imputation_methods,
  author = {Ribeiro, Diogo},
  title = {imputation-methods: A Unified pandas API for Missing-Data Imputation},
  year = {2024},
  url = {https://github.com/DiogoRibeiro7/imputation-methods}
}