Skip to main content

RobustPreprocessor

RobustPreprocessor is a Python package for comprehensive and flexible data preprocessing. It is designed to clean and prepare numeric datasets for machine learning and analysis by handling outliers, missing values, infinity values, and redundant features.


Features

  • Outlier Handling:

    • Interquartile Range (IQR) clipping.
    • Z-score filtering.
  • Infinity Value Handling:

    • Replace with finite extremes.
    • Drop rows containing infinity.
    • Replace with a specific default value (e.g., 0).
  • Missing Value Imputation:

    • Mean, median, or most frequent value strategies.
  • Feature Removal:

    • Drop constant or near-constant features.
  • Visualization:

    • Plot feature distributions with histograms.
  • Execution Logging:

    • Outputs a JSON summary of preprocessing steps, including dropped columns and execution time.

Installation

Install via pip:

pip install robustpreprocessor

Or clone the repository and install locally:

git clone https://github.com/nqmn/robustpreprocessor.git
cd robustpreprocessor
pip install .

Usage

Import the Package

from robustpreprocessor import RobustPreprocessor
import pandas as pd

# Example dataset
data = pd.DataFrame({
    "feature_1": [1, 2, 3, 1000, 5],
    "feature_2": [1, 2, None, 4, 5],
    "feature_3": [0, 0, 0, 0, 0],
    "feature_4": [1, 2, np.inf, -np.inf, 5],
})

# Initialize the preprocessor
preprocessor = RobustPreprocessor(verbose=True)

# Preprocess the dataset
cleaned_data = preprocessor.preprocess(
    data,
    outlier_method="IQR",
    infinity_handling="set_value",
    missing_value_strategy="mean",
    feature_removal_criteria="constant"
)

# View the cleaned data
print(cleaned_data)

Visualization

Use the plot_feature_distributions method to visualize the distributions of numeric features:

preprocessor.plot_feature_distributions(cleaned_data)

Logging and Execution Summary

After preprocessing, the class outputs a JSON log summarizing the steps taken, including execution time and dropped columns:

{
    "process_type": "RobustPreprocessor",
    "user_selections": {
        "outlier_method": "IQR",
        "infinity_handling": "set_value",
        "missing_value_strategy": "mean",
        "feature_removal_criteria": "constant"
    },
    "steps_executed": {
        "select_numeric_columns": "Selected 4 numeric columns",
        "outlier_handling": "Handled outliers using IQR method.",
        "infinity_handling": "Replaced infinity values with a set value (0).",
        "missing_value_imputation": "Imputed missing values with mean strategy.",
        "feature_removal": "Dropped 1 constant columns."
    },
    "dropped_columns": 1,
    "execution_time_seconds": 0.1234
}

Dependencies

  • numpy
  • pandas
  • scikit-learn
  • matplotlib
  • scipy

Install them with:

pip install -r requirements.txt

Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Commit your changes with clear descriptions.
  4. Submit a pull request.

License

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


Support

If you encounter issues or have questions, feel free to open an issue on GitHub.


Acknowledgments

  • Inspired by common challenges in data preprocessing.
  • Thanks to the contributors and the open-source community!

Metadata

Release files for robustpreprocessor 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for robustpreprocessor 1.0.0
File Size Uploaded
robustpreprocessor-1.0.0.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for robustpreprocessor 1.0.0
File Interpreter ABI Platform
robustpreprocessor-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 13.5 kB

Release files / robustpreprocessor-1.0.0.tar.gz

Download URL robustpreprocessor-1.0.0.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
13768a47a1528b89b669e4fc6f5cf02a8171a0b783a277eca0e6e2c012e7f2c2
BLAKE2b-256 checksum
How to use checksums
41e4329ceb49b1176a13a1f2f631fa48ca92bfdd113d743a37108fba69a19897
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Release files / robustpreprocessor-1.0.0-py3-none-any.whl

Download URL robustpreprocessor-1.0.0-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a44fb3bb47994a1496e19db3031c259b2d81b24dbbc2589ca475f4d06052e041
BLAKE2b-256 checksum
How to use checksums
f257b6b01d00dd3a290e679b237ff1ff224822f2ad661b38bad6d869cae8192f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.12.2

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page