Name | mgp-imputer JSON |
Version |
0.1.2
JSON |
| download |
home_page | None |
Summary | Missing Value Imputation using Deep Gaussian Processes with a scikit-learn compatible API. |
upload_time | 2025-08-21 21:16:24 |
maintainer | None |
docs_url | None |
author | None |
requires_python | >=3.8 |
license | MIT License
Copyright (c) 2022 BahramJafrasteh
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
|
keywords |
gaussian process
imputation
missing data
clinical data
pytorch
healthcare
|
VCS |
 |
bugtrack_url |
|
requirements |
missingpy
numpy
pandas
pkbar
torch
matplotlib
fancyimpute
rpy2
scipy
scikit_learn
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# MGP-Imputer: Missing Value Imputation with Deep Gaussian Processes
[](https://badge.fury.io/py/mgp-imputer)
[](https://opensource.org/licenses/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"](https://www.sciencedirect.com/science/article/pii/S0950705123003532).
<p align="center">
<img src="https://raw.githubusercontent.com/BahramJafrasteh/MissingGPs/main/mgp.png" alt="MELAGE Demo" width="600"/><br>
<p align="center">
<em>Chained Deep Gaussian Processes for Missing Value Imputation</em>
</p>
</p>
## 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:
```bash
pip install mgp-imputer
```
## **Quick Start**
Here's how to use `MGPImputer` to fill in missing values (`np.nan`) in your dataset.
```bash
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=100,
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())
```
## Configuration Options
You can customize the behavior of `MGPImputer` by passing parameters during initialization. Here are the available options:
| Parameter | Description | Type | Options | Default |
|---|---|---|---|---|
| `imputation_strategy` | The core method for building the GP model. | `str` | `'chained'`, `'holistic'` | `'chained'` |
| `imp_init` | The standard imputation method used to create an initial complete dataset before training the GP. | `str` | `'mean'`, `'median'`, `'knn'`, `'mice'`, `'constant'` | `'mean'` |
| `kernel` | The covariance function for the Gaussian Process layers. | `str` | `'matern'`, `'rbf'` | `'matern'` |
| `n_layers` | The number of layers in the Deep GP. Only used when `imputation_strategy` is `'holistic'`. | `int` | `> 0` | `2` |
| `n_inducing_points` | The number of inducing points for the sparse GP approximation. A higher number is more accurate but computationally slower. | `int` | `> 0` | `100` |
| `n_iterations` | The total number of optimization iterations to run during training. | `int` | `> 0` | `10000` |
| `n_samples` | The number of Monte Carlo samples drawn to approximate the model's posterior distribution. | `int` | `> 0` | `20` |
| `learning_rate` | The learning rate for the Adam optimizer. | `float` | `> 0` | `0.01` |
| `batch_size` | The number of data points in each mini-batch during training. | `int` | `> 0` | `128` |
| `likelihood_var` | The initial variance of the Gaussian likelihood function. | `float` | `> 0` | `0.01` |
| `var_noise` | The initial variance of the white noise added to the kernel. | `float` | `> 0` | `0.0001` |
| `verbose` | If `True`, prints training progress and other information. | `bool` | `True`, `False` | `True` |
| `use_cuda` | If `True`, the model will run on a GPU if one is available. | `bool` | `True`, `False` | `True` |
| `seed` | A random seed for reproducibility of results. | `int` | `≥ 0` | `0` |
## **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](https://www.sciencedirect.com/science/article/pii/S0950705123003532)
## License
This project is licensed under the MIT License.
Raw data
{
"_id": null,
"home_page": null,
"name": "mgp-imputer",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "gaussian process, imputation, missing data, clinical data, pytorch, healthcare",
"author": null,
"author_email": "Bahram Jafrasteh <baj4003@med.cornell.edu>",
"download_url": "https://files.pythonhosted.org/packages/0d/0c/6ea3f98f3cbd947ce614064fd908593dcaa3f7eccec0bc2fb5f9380096c3/mgp_imputer-0.1.2.tar.gz",
"platform": null,
"description": "# MGP-Imputer: Missing Value Imputation with Deep Gaussian Processes\n[](https://badge.fury.io/py/mgp-imputer)\n[](https://opensource.org/licenses/MIT)\n\nA PyTorch-based implementation of Missing Gaussian Processes (MGP) for missing value imputation, wrapped in a user-friendly `scikit-learn` compatible API.\n\nThis 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\"](https://www.sciencedirect.com/science/article/pii/S0950705123003532).\n\n<p align=\"center\">\n <img src=\"https://raw.githubusercontent.com/BahramJafrasteh/MissingGPs/main/mgp.png\" alt=\"MELAGE Demo\" width=\"600\"/><br>\n <p align=\"center\">\n <em>Chained Deep Gaussian Processes for Missing Value Imputation</em> \n </p>\n</p>\n\n## Features\n\n- **Scikit-learn Compatible:** Use `fit`, `predict`, and `fit_transform` methods just like any other scikit-learn transformer.\n- **Two Imputation Strategies:**\n - `chained` (Default): Builds a separate GP layer for each feature with missing values, modeling dependencies in a chained fashion (MGP).\n - `holistic`: Builds a single, multi-output Deep GP to model all features simultaneously.\n- **Probabilistic Imputation:** Returns both the imputed values and the standard deviation, giving you a measure of uncertainty for each imputed value.\n- **GPU Accelerated:** Leverages PyTorch to run on CUDA devices for significant speedups.\n\n## Installation\n\nYou can install `mgp-imputer` directly from PyPI:\n\n```bash\npip install mgp-imputer\n```\n\n\n\n## **Quick Start**\nHere's how to use `MGPImputer` to fill in missing values (`np.nan`) in your dataset.\n```bash\nimport numpy as np\nimport pandas as pd\nfrom mgp import MGPImputer\n\n# 1. Create a synthetic dataset with 20% missing values\nnp.random.seed(42)\nn_samples, n_features = 200, 5\nX_true = np.random.rand(n_samples, n_features) * 10\nX_missing = X_true.copy()\nmissing_mask = np.random.rand(n_samples, n_features) < 0.2\nX_missing[missing_mask] = np.nan\n\nprint(f\"Created a dataset with {np.sum(missing_mask)} missing values.\")\n\n# 2. Initialize the MGPImputer\n# Strategies can be 'chained' (default) or 'holistic'\nimputer = MGPImputer(\n imputation_strategy='chained',\n n_inducing_points=100,\n n_iterations=1000, # Use more iterations for real data\n learning_rate=0.01,\n batch_size=64,\n verbose=True,\n seed=42\n)\n\n# 3. Fit on the data and transform it to get imputed values\n# The imputer returns the imputed data and the standard deviation of the predictions\nX_imputed, X_std = imputer.fit_transform(X_missing)\n\n# 4. Evaluate the imputation quality\nrmse = np.sqrt(np.mean((X_imputed[missing_mask] - X_true[missing_mask])**2))\nprint(f\"\\nImputation complete.\")\nprint(f\"RMSE on missing values: {rmse:.4f}\")\n\n# The result is a complete numpy array\nprint(\"\\nImputed data shape:\", X_imputed.shape)\nprint(\"Number of NaNs in imputed data:\", np.isnan(X_imputed).sum())\n```\n\n## Configuration Options\n\nYou can customize the behavior of `MGPImputer` by passing parameters during initialization. Here are the available options:\n\n| Parameter | Description | Type | Options | Default |\n|---|---|---|---|---|\n| `imputation_strategy` | The core method for building the GP model. | `str` | `'chained'`, `'holistic'` | `'chained'` |\n| `imp_init` | The standard imputation method used to create an initial complete dataset before training the GP. | `str` | `'mean'`, `'median'`, `'knn'`, `'mice'`, `'constant'` | `'mean'` |\n| `kernel` | The covariance function for the Gaussian Process layers. | `str` | `'matern'`, `'rbf'` | `'matern'` |\n| `n_layers` | The number of layers in the Deep GP. Only used when `imputation_strategy` is `'holistic'`. | `int` | `> 0` | `2` |\n| `n_inducing_points` | The number of inducing points for the sparse GP approximation. A higher number is more accurate but computationally slower. | `int` | `> 0` | `100` |\n| `n_iterations` | The total number of optimization iterations to run during training. | `int` | `> 0` | `10000` |\n| `n_samples` | The number of Monte Carlo samples drawn to approximate the model's posterior distribution. | `int` | `> 0` | `20` |\n| `learning_rate` | The learning rate for the Adam optimizer. | `float` | `> 0` | `0.01` |\n| `batch_size` | The number of data points in each mini-batch during training. | `int` | `> 0` | `128` |\n| `likelihood_var` | The initial variance of the Gaussian likelihood function. | `float` | `> 0` | `0.01` |\n| `var_noise` | The initial variance of the white noise added to the kernel. | `float` | `> 0` | `0.0001` |\n| `verbose` | If `True`, prints training progress and other information. | `bool` | `True`, `False` | `True` |\n| `use_cuda` | If `True`, the model will run on a GPU if one is available. | `bool` | `True`, `False` | `True` |\n| `seed` | A random seed for reproducibility of results. | `int` | `\u2265 0` | `0` |\n\n## **Citation**\nIf you use this work in your research, please cite the original paper:\n\nJafrasteh, B., Hern\u00e1ndez-Lobato, D., Lubi\u00e1n-L\u00f3pez, S. P., & Benavente-Fern\u00e1ndez, I. (2023). Gaussian processes for missing value imputation. Knowledge-Based Systems, 273, 110603.\n[Missing GPs](https://www.sciencedirect.com/science/article/pii/S0950705123003532)\n\n\n\n## License\n\nThis project is licensed under the MIT License.\n\n",
"bugtrack_url": null,
"license": "MIT License\n \n Copyright (c) 2022 BahramJafrasteh\n \n Permission is hereby granted, free of charge, to any person obtaining a copy\n of this software and associated documentation files (the \"Software\"), to deal\n in the Software without restriction, including without limitation the rights\n to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\n copies of the Software, and to permit persons to whom the Software is\n furnished to do so, subject to the following conditions:\n \n The above copyright notice and this permission notice shall be included in all\n copies or substantial portions of the Software.\n \n THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\n IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\n FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\n AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\n LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\n OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\n SOFTWARE.\n ",
"summary": "Missing Value Imputation using Deep Gaussian Processes with a scikit-learn compatible API.",
"version": "0.1.2",
"project_urls": {
"Bug Tracker": "https://github.com/BahramJafrasteh/MissingGPs/issues",
"Homepage": "https://github.com/BahramJafrasteh/MissingGPs"
},
"split_keywords": [
"gaussian process",
" imputation",
" missing data",
" clinical data",
" pytorch",
" healthcare"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "fd8d4e8b2220573edca1a353791e4a10a361513c37757794d4c09faf802be476",
"md5": "0856f7697726c6d6a54f16535e35f4dd",
"sha256": "786fa3e9e1eb7ba80ac4380421da864cba81014fad350b7154e6455fc14d3780"
},
"downloads": -1,
"filename": "mgp_imputer-0.1.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "0856f7697726c6d6a54f16535e35f4dd",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 38436,
"upload_time": "2025-08-21T21:16:23",
"upload_time_iso_8601": "2025-08-21T21:16:23.121480Z",
"url": "https://files.pythonhosted.org/packages/fd/8d/4e8b2220573edca1a353791e4a10a361513c37757794d4c09faf802be476/mgp_imputer-0.1.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "0d0c6ea3f98f3cbd947ce614064fd908593dcaa3f7eccec0bc2fb5f9380096c3",
"md5": "00e0975944fa97b0b6c17a655a801967",
"sha256": "168c87b5eb013eca1648ec3a8400ff6dca0ff609972f33b75dce35da8a69895b"
},
"downloads": -1,
"filename": "mgp_imputer-0.1.2.tar.gz",
"has_sig": false,
"md5_digest": "00e0975944fa97b0b6c17a655a801967",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 35455,
"upload_time": "2025-08-21T21:16:24",
"upload_time_iso_8601": "2025-08-21T21:16:24.387225Z",
"url": "https://files.pythonhosted.org/packages/0d/0c/6ea3f98f3cbd947ce614064fd908593dcaa3f7eccec0bc2fb5f9380096c3/mgp_imputer-0.1.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-08-21 21:16:24",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "BahramJafrasteh",
"github_project": "MissingGPs",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "missingpy",
"specs": [
[
"==",
"0.2.0"
]
]
},
{
"name": "numpy",
"specs": [
[
"==",
"1.19.5"
]
]
},
{
"name": "pandas",
"specs": [
[
"==",
"1.1.5"
]
]
},
{
"name": "pkbar",
"specs": [
[
"==",
"0.5"
]
]
},
{
"name": "torch",
"specs": [
[
"==",
"1.10.0+cu113"
]
]
},
{
"name": "matplotlib",
"specs": [
[
"==",
"3.3.0"
]
]
},
{
"name": "fancyimpute",
"specs": [
[
"==",
"0.7.0"
]
]
},
{
"name": "rpy2",
"specs": [
[
"==",
"3.4.5"
]
]
},
{
"name": "scipy",
"specs": [
[
"==",
"1.5.0"
]
]
},
{
"name": "scikit_learn",
"specs": [
[
"==",
"1.0.2"
]
]
}
],
"lcname": "mgp-imputer"
}