Explainable preprocessing for ML pipelines with reports and visualizations.
Project description
ml-explain-preprocess
Transparent preprocessing for machine learning with beginner-friendly reports and visualizations.
ml-explain-preprocess simplifies data preprocessing for machine learning by providing modular functions to handle missing values, encoding, scaling, outlier detection, and feature selection. Each step generates detailed, easy-to-understand reports (text or JSON) and optional visualizations, making it ideal for beginners and teams needing auditable pipelines.
Installation
Install from PyPI with:
pip install ml-explain-preprocess
Requires Python 3.8+ and dependencies: pandas, numpy, scikit-learn, matplotlib, seaborn.
Why ml-explain-preprocess?
Preprocessing is a critical but often opaque step in machine learning. This package makes it transparent by:
- Explaining every transformation to clarify what each step does.
- Generating detailed reports with before/after stats, impacts, and beginner tips.
- Visualizing changes with plots (e.g., missing value heatmaps, histograms).
- Seamless integration with pandas DataFrames, compatible with scikit-learn pipelines.
This package is designed for beginners learning data preparation and teams requiring auditable workflows.
Key Features
- Missing Value Handling: Impute with mean, median, mode, or constant; reports percentage of missing data handled.
- Encoding: One-hot or label encoding for categorical features, with unique value counts.
- Scaling: Min-max, standard, or robust scaling, with detailed before/after statistics.
- Outlier Detection: IQR or z-score methods, with options to remove, clip, or report outliers.
- Feature Selection: Drop low-variance features, with variance reports.
- Explainable Reports: Beginner-friendly explanations, parameters, impacts, stats, and visual descriptions in text or JSON.
- Visualizations: Save plots (e.g., histograms, boxplots) to a
reports/folder whenvisual=True. - Pandas Integration: Input/output as DataFrames for easy use in ML workflows.
Quickstart
import pandas as pd
from ml_explain_preprocess import explain_preprocess
# Sample dataset
df = pd.DataFrame({
'Age': [25, 30, None, 40],
'Gender': ['M', 'F', 'M', 'F'],
'Income': [50000, 60000, 55000, None]
})
# Run preprocessing pipeline
processed_df, report = explain_preprocess(
df,
steps=['fill', 'encode', 'scale'],
report_format='text',
visual=True
)
# View report
print(report)
Example text report output:
Preprocessing Report (Beginner-Friendly)
====================================
Step: FILL
Explanation: Missing value handling (imputation) fills in gaps in the data to ensure machine learning models can process it. Missing data can occur due to errors or incomplete collection.
Parameters Used: Strategy: auto, Columns: ['Age', 'Income']
Impact: Handled 2 missing values (16.7% of data).
Statistics:
missing_before: {'Age': '1 missing (25.0%)', 'Income': '1 missing (25.0%)'}
missing_after: {'Age': '0 missing (0%)', 'Income': '0 missing (0%)'}
strategies: {'Age': 'median', 'Income': 'median'}
Visuals: reports/missing_before.png, reports/missing_after.png
Visual Descriptions:
- Heatmap (before): Red/yellow shows missing values, white is non-missing.
- Heatmap (after): Should be all white if all missing values were filled.
Tips for Beginners: Choose 'median' for numerical data with outliers, 'mean' for normally distributed data, or 'mode' for categorical data. Always check how much data is missing before imputing.
----------------------------------------
[... more steps ...]
Visualizations (when visual=True) are saved to the reports/ folder.
Available Functions
explain_fill_missing(df, strategy='auto', columns=None, visual=False): Impute missing values.explain_encode(df, method='auto', columns=None, visual=False): Encode categorical features.explain_scale(df, method='minmax', columns=None, visual=False): Scale numerical features.explain_outliers(df, method='iqr', threshold=1.5, action='remove', columns=None, visual=False): Handle outliers.explain_select_features(df, threshold=0.01, columns=None, visual=False): Drop low-variance features.explain_preprocess(df, steps=['fill', 'encode', 'scale', 'outliers', 'select'], target=None, report_format='json', visual=False): Full pipeline with combined report.
Each function returns: processed_df, report_dict.
Project Structure
ml-explain-preprocess/
├── ml_explain_preprocess/
│ ├── __init__.py
│ ├── preprocess.py # Core preprocessing functions
│ └── reports.py # Report generator
├── tests/ # Unit tests
├── examples/ # Example Jupyter notebook
├── pyproject.toml # Package configuration
├── LICENSE # MIT License
└── README.md
Contributing
We welcome contributions! To get started:
- Fork the repository on GitHub.
- Submit issues or pull requests for bugs, features, or improvements.
- Contact: backpropnomad@gmail.com.
License
Released under the MIT License.
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 ml_explain_preprocess-0.1.1.tar.gz.
File metadata
- Download URL: ml_explain_preprocess-0.1.1.tar.gz
- Upload date:
- Size: 15.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3e2107b5e988d7b5586ee7bab1e6586dcf82de4424618c4bf0eefdf72faa0ea1
|
|
| MD5 |
64eafe3d7878e02e830c8eb54a5762ac
|
|
| BLAKE2b-256 |
5d3b7e34cdaaef058ead842a6fb648a6829123b9d532b416f91800c0f3d9ed6b
|
File details
Details for the file ml_explain_preprocess-0.1.1-py3-none-any.whl.
File metadata
- Download URL: ml_explain_preprocess-0.1.1-py3-none-any.whl
- Upload date:
- Size: 12.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5a874816f34637bed86e1ce8405144b9025897c4bf5ec1a8180608eeba0c5d6f
|
|
| MD5 |
5b90df197bbac018cf3dd5b6c517d7db
|
|
| BLAKE2b-256 |
ed679dc2eb2073a403b961d0d234cd96908544a8240e5d5914b53c0bd2731453
|