Best imputation method.
Project description
MissForest
This project is a Python implementation of the MissForest algorithm, a powerful tool designed to handle missing values in tabular datasets. The primary goal of this project is to provide users with a more accurate method of imputing missing data.
While MissForest may take more time to process datasets compared to simpler imputation methods, it typically yields more accurate results.
Please note that the efficiency of MissForest is a trade-off for its accuracy. It is designed for those who prioritize data accuracy over processing speed. This makes it an excellent choice for projects where the quality of data is paramount.
How MissForest Handles Categorical Variables ?
Categorical variables in argument 'categoricals' will be label encoded for estimators to work properly.
Example
To install MissForest using pip.
pip install MissForest
Imputing a dataset:
from missforest.missforest import MissForest
import pandas as pd
import numpy as np
if __name__ == "__main__":
df = pd.read_csv("insurance.csv")
# default estimators are lgbm classifier and regressor
mf = MissForest()
df_imputed = mf.fit_transform(df)
Imputing with other estimators
from missforest.missforest import MissForest
import pandas as pd
import numpy as np
from sklearn.ensemble import RandomForestRegressor, RandomForestClassifier
if __name__ == "__main__":
df = pd.read_csv("insurance.csv")
df_or = df.copy()
for c in df.columns:
random_index = np.random.choice(df.index, size=100)
df.loc[random_index, c] = np.nan
clf = RandomForestClassifier(n_jobs=-1)
rgr = RandomForestRegressor(n_jobs=-1)
mf = MissForest(clf, rgr)
df_imputed = mf.fit_transform(df)
Benchmark
Mean Absolute Percentage Error
missForest | mean/mode | Difference
charges 2.65% 9.72% -7.07%
age 1.16% 2.77% -1.61%
bmi 1.18% 1.25% -0.07%
sex 21.21 31.82 -10.61
smoker 4.24 9.90 -5.66
region 46.67 38.96 +7.71
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file MissForest-2.2.1.tar.gz
.
File metadata
- Download URL: MissForest-2.2.1.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0rc2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | bea9ab492a674aaf7e4020ce6d57670ec79ddd7d891aacf6449883814cdbd1b7 |
|
MD5 | 8c2b60cd691339f3126b85bdccc1593a |
|
BLAKE2b-256 | f32e056cd4a804547b01aa4fba3685285172862aec7a0a38d9fd6cf97ac3d6ed |
File details
Details for the file MissForest-2.2.1-py3-none-any.whl
.
File metadata
- Download URL: MissForest-2.2.1-py3-none-any.whl
- Upload date:
- Size: 7.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.0rc2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | b419a44d1437aea0bcc515fd219041d136d016f263f59f54ea387351bafe062c |
|
MD5 | c4bbe6943f0efa6de050717d99f2e7cf |
|
BLAKE2b-256 | 47798e6fe8d80aabe4489e0305336330a6326b5a1cb057379505a5501040cfdd |