Machine learning audit trail and reproducibility utilities
Project description
ML Audit 📊
Track, Audit, and Visualize your Machine Learning Preprocessing Pipelines.
ml-audit is a lightweight Python library designed to bring transparency and reproducibility to data preprocessing. It records every transformation applied to your pandas DataFrame, ensures scientific reproducibility, and automatically generates beautiful HTML visualizations of your data lineage.
✨ Features
- Full Audit Trail: Automatically logs every step (Imputation, Scaling, Encoding, etc.) into a JSON audit file.
- Reproducibility: Verify if your data pipeline produces the exact same result every time.
- Visualization: Auto-generates an interactive HTML timeline of your preprocessing steps.
- Comprehensive Operations:
- Imputation:
mean,median,mode,constant,ffill,bfill. - Scaling:
minmax,standard,robust,maxabs. - Encoding:
onehot,label,targetencoding. - Balancing:
smote(via imblearn),oversample(random),undersample. - Transformation:
log,sqrt,boxcox, etc. - Date Extraction: Extract year, month, day, etc. from timestamps.
- Imputation:
- Multi-Column Support: Apply operations to lists of columns efficiently.
- Generic Support: Track any arbitrary pandas method (e.g.,
dropna,rename).
🚀 Installation
You can install ml-audit via pip:
pip install ml-audit
For SMOTE balancing support, install with the balance extra:
pip install ml-audit[balance]
📖 Quick Start
1. Initialize the Recorder
import pandas as pd
from ml_audit import AuditTrialRecorder
# Load your data
df = pd.read_csv("data.csv")
# Initialize the auditor wrapped around your dataframe
auditor = AuditTrialRecorder(df, name="experiment_v1")
2. Apply Preprocessing
Chain methods fluently. Operations are applied immediately to auditor.current_df.
auditor.filter_rows("age", ">=", 18) \
.impute(["salary", "score"], strategy='median') \
.scale(["salary", "age"], method='minmax') \
.encode("gender", method='onehot') \
.balance_classes("churn", strategy='oversample') # Hands imbalanced data
3. Access Data
processed_df = auditor.current_df
print(processed_df.head())
4. Export & Visualize
Save the audit trail. This will generate a JSON file (audit_trails/) and an HTML visualization (visualizations/).
auditor.export_audit_trail("audit.json")
# Output:
# - audit_trails/audit.json
# - visualizations/audit.html
📚 Detailed Documentation
Multi-Column Operations
All major preprocessing methods accept either a single string or a list of strings for column names.
# Scale multiple columns at once
auditor.scale(["height", "weight", "bmi"], method='standard')
Generic Pandas Tracking
For operations not natively built-in, use track_pandas to record any DataFrame method.
# Track a rename operation
auditor.track_pandas("rename", columns={"old_name": "new_name"})
# Track dropping NaNs
auditor.track_pandas("dropna", subset=["critical_col"])
Reproducibility Check
Verify that replaying your logs produces the exact same data hash as the current state.
if auditor.verify_reproducibility():
print("Pipeline is scientifically reproducible! ✅")
else:
print("Pipeline result mismatch! ❌")
🎨 Visualization
Open the generated HTML file in visualizations/ to see a timeline like this:
- Step 1: Load Data (Shape: 1000x5)
- Step 2: Impute (
salary-> median) - Step 3: Scale (
age-> minmax) - ...
📄 License
MIT License. Free to use for personal and commercial projects.
Project details
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_audit-0.1.0.tar.gz.
File metadata
- Download URL: ml_audit-0.1.0.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2a65cfb34f2e552bf186d310bbca0b7b8acef59748c26bd4d4f5ccf3acb92996
|
|
| MD5 |
659b71bbfecbe46ec140b6ad9991678c
|
|
| BLAKE2b-256 |
0afddc9e3621fa3fecad7a6ca2b0f93df650a35055fe24b8672b131c45cfb26d
|
File details
Details for the file ml_audit-0.1.0-py3-none-any.whl.
File metadata
- Download URL: ml_audit-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f9d727e420be90f1330504174051b1016809072685002e3f91cbd587a2686260
|
|
| MD5 |
26b51bebe5eac152e841b3d0ca71e6fa
|
|
| BLAKE2b-256 |
fef33c5d43df6b06df3203b43edc8e6d05c09bc030c9b4be85b8b70496a0f052
|