Skip to main content

Missing Value Imputation using Deep Gaussian Processes with a scikit-learn compatible API.

Project description

MGP-Imputer: Missing Value Imputation with Deep Gaussian Processes

PyPI version License: MIT

A PyTorch-based implementation of Missing Gaussian Processes (MGP) for missing value imputation, wrapped in a user-friendly scikit-learn compatible API.

This package allows you to seamlessly integrate Deep Gaussian Process models into your data preprocessing pipelines for robust and uncertainty-aware imputation. It is based on the paper "Gaussian processes for missing value imputation".

Features

  • Scikit-learn Compatible: Use fit, predict, and fit_transform methods just like any other scikit-learn transformer.
  • Two Imputation Strategies:
    • chained (Default): Builds a separate GP layer for each feature with missing values, modeling dependencies in a chained fashion (MGP).
    • holistic: Builds a single, multi-output Deep GP to model all features simultaneously.
  • Probabilistic Imputation: Returns both the imputed values and the standard deviation, giving you a measure of uncertainty for each imputed value.
  • GPU Accelerated: Leverages PyTorch to run on CUDA devices for significant speedups.

Installation

You can install mgp-imputer directly from PyPI:

pip install mgp-imputer

Quick Start

Here's how to use MGPImputer to fill in missing values (np.nan) in your dataset.

import numpy as np
import pandas as pd
from mgp import MGPImputer

# 1. Create a synthetic dataset with 20% missing values
np.random.seed(42)
n_samples, n_features = 200, 5
X_true = np.random.rand(n_samples, n_features) * 10
X_missing = X_true.copy()
missing_mask = np.random.rand(n_samples, n_features) < 0.2
X_missing[missing_mask] = np.nan

print(f"Created a dataset with {np.sum(missing_mask)} missing values.")

# 2. Initialize the MGPImputer
# Strategies can be 'chained' (default) or 'holistic'
imputer = MGPImputer(
    imputation_strategy='chained',
    n_inducing_points=1000,
    n_iterations=1000, # Use more iterations for real data
    learning_rate=0.01,
    batch_size=64,
    verbose=True,
    seed=42
)

# 3. Fit on the data and transform it to get imputed values
# The imputer returns the imputed data and the standard deviation of the predictions
X_imputed, X_std = imputer.fit_transform(X_missing)

# 4. Evaluate the imputation quality
rmse = np.sqrt(np.mean((X_imputed[missing_mask] - X_true[missing_mask])**2))
print(f"\nImputation complete.")
print(f"RMSE on missing values: {rmse:.4f}")

# The result is a complete numpy array
print("\nImputed data shape:", X_imputed.shape)
print("Number of NaNs in imputed data:", np.isnan(X_imputed).sum())

Citation

If you use this work in your research, please cite the original paper:

Jafrasteh, B., Hernández-Lobato, D., Lubián-López, S. P., & Benavente-Fernández, I. (2023). Gaussian processes for missing value imputation. Knowledge-Based Systems, 273, 110603. Missing GPs

Getting Started

Prerequisites

Install the dependencies using the following command:

pip install -r requirements.txt

Using the code

Put your data in "datasets" folder and run your experiments using the following command with optional arguments.

python run_experiment.py -h
  -h, --help            show this help message and exit
  --dataset_name DATASET_NAME
                        name of the data set (should have subfolders with the
                        name s0, s1, s2, etc.) (default: None)
  --scaling SCALING     scaling method [MeanStd|MinMax|MaxAbs|Robust|None]
                        (default: MeanStd)
  --split_number split_number
                        data set split number [0|1|2|etc] (default: 0)
  --name svgp           svgp
  --nGPU NGPU           GPU number (for cpu use -1) [-1|0|1|2] (default: -1)
  --minibatch_size BATCHSIZE
                        Batch size (default: 100) (default: 100)
  --M NIP             number of inducing points (default: 100) (default:
                        1024)
  --M2 NIP2             number of inducing points (default: 100) (default:
                        1024)
  --imputation mean     mean|median|knn|mice|None
  
  --kernel              Matern|RBF (defaults:matern)
  
  --likelihood_var      variance noise gaussian likelihood (0.01)
  
  --lrate               learning rate (0.01)
  
  --missing             consider missing (should be on for MGP, otherwise return normal SVGP)
  
  --nGPU                GPU number
  
  --n_epoch             number of training epochs
  
  --n_samples           number of MC samples
  
  --nolayers            number of layers
  
  --numThreads          number of threads
  
  --var_noise           variance noise
  
  --consider_miss       consider missing for DGP and VSGP

You can run experiments using UCI data set with the above options. To replicate results from the paper:

python run_experiment.py --dataset_name parkinson_10 --lrate 0.01 --split_number 0 --name svgp --n_samples 20 --M 100 --M2 100 --no_iterations 10000 --nolayers 1 --nGPU 0 --minibatch_size 100 --fitting --imputation mean --missing

Cite

Jafrasteh, B., Hernández-Lobato, D., Lubián-López, S. P., & Benavente-Fernández, I. (2023). Gaussian processes for missing value imputation. Knowledge-Based Systems, 273, 110603. Missing GPs

License

This project is licensed under the MIT License.

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

mgp_imputer-0.0.1.tar.gz (33.8 kB view details)

Uploaded Source

Built Distribution

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

mgp_imputer-0.0.1-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file mgp_imputer-0.0.1.tar.gz.

File metadata

  • Download URL: mgp_imputer-0.0.1.tar.gz
  • Upload date:
  • Size: 33.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for mgp_imputer-0.0.1.tar.gz
Algorithm Hash digest
SHA256 d7eabdac9b9e924af7efaa83ae49b09d7cb8f24885b60ee448fb9b4bf755b1e2
MD5 bc0f5d2faa88c0c16b6a9b910083504b
BLAKE2b-256 92c4298bdfc24d1cd1c0bac10b18e09f0273df23f35095ae1c95391bf3478233

See more details on using hashes here.

File details

Details for the file mgp_imputer-0.0.1-py3-none-any.whl.

File metadata

  • Download URL: mgp_imputer-0.0.1-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.10.12

File hashes

Hashes for mgp_imputer-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 8231b6c13913abb2e1137b90696db7a23d6ee3b51d02f6dc843a6ea73dd94bd3
MD5 0133b97c528c565ffa6ca37b10cbd073
BLAKE2b-256 893b859a13531d16752c6577191322f0c2f70d10af6af837e7ccc3b88931328e

See more details on using hashes here.

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