A python package for easy data imputation
Project description
DataFiller is a Python library for imputing missing values in datasets. It provides a flexible and powerful way to handle missing data in both numerical arrays and time series data.
Key Features
- Model-Based Imputation: Uses machine learning models (like linear regression) to predict and fill missing values.
- Time Series Support: A dedicated
TimeSeriesImputerthat automatically creates lagged and lead features for imputation. - Efficient: Leverages Numba for performance-critical sections.
- Smart Feature Selection: Finds the optimal subset of data to use for training imputation models.
- Scikit-Learn Compatible: Integrates with the scikit-learn ecosystem.
Installation
You can install DataFiller using pip:
pip install datafiller
Basic Usage
Imputing a NumPy Array
The MultivariateImputer can be used to fill missing values (NaN) in a 2D NumPy array.
import numpy as np
from datafiller import MultivariateImputer
# Create a matrix with missing values
X = np.array([
[1.0, 2.0, 3.0, 4.0],
[5.0, np.nan, 7.0, 8.0],
[9.0, 10.0, 11.0, np.nan],
[13.0, 14.0, 15.0, 16.0],
])
# Initialize the imputer and fill the missing values
imputer = MultivariateImputer()
X_imputed = imputer(X)
print("Original Matrix:")
print(X)
print("\nImputed Matrix:")
print(X_imputed)
Imputing a Time Series DataFrame
The TimeSeriesImputer is designed to work with pandas DataFrames that have a DatetimeIndex. It automatically creates autoregressive features (lags and leads) to improve imputation accuracy.
import pandas as pd
import numpy as np
from datafiller import TimeSeriesImputer
# Create a time series DataFrame with missing values
rng = pd.date_range('2023-01-01', periods=10, freq='D')
data = {
'feature1': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'feature2': [10, 9, np.nan, 7, 6, 5, np.nan, 3, 2, 1],
}
df = pd.DataFrame(data, index=rng)
# Initialize the imputer with lags and leads
# Use t-1 and t+1 to impute missing values
ts_imputer = TimeSeriesImputer(lags=[1, -1])
df_imputed = ts_imputer(df)
print("Original DataFrame:")
print(df)
print("\nImputed DataFrame:")
print(df_imputed)
How It Works
DataFiller uses a model-based imputation strategy. For each column containing missing values, it trains a regression model using the other columns as features. The rows used for training are carefully selected to be the largest, most complete rectangular subset of the data, which is found using the optimask algorithm. This ensures that the training data is of the highest possible quality, leading to more accurate imputations.
For more details, see the documentation.
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
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 datafiller-0.1.3.tar.gz.
File metadata
- Download URL: datafiller-0.1.3.tar.gz
- Upload date:
- Size: 28.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a33de77a2fff057fb7b14675795f948671cdd0039d78fb660325d242aaa62f40
|
|
| MD5 |
b3c7698459a15d4bcb29e7c888963c81
|
|
| BLAKE2b-256 |
c7b3b3320ef9d8e315ff45b3f27d514536af72feb8bb024fc7d58dd9508a12ec
|
File details
Details for the file datafiller-0.1.3-py2.py3-none-any.whl.
File metadata
- Download URL: datafiller-0.1.3-py2.py3-none-any.whl
- Upload date:
- Size: 25.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d3c3b4ac05ef32a0e720302fff73cc8458e771e1da46570ec9f3862e9f71141e
|
|
| MD5 |
b97383ac3c1521c817a00cfd30642619
|
|
| BLAKE2b-256 |
672b99d374cb1036449fda3cb2a641939ad1e3b056433bb9db5fc614177c9591
|