Reusable ML utilities focused on leakage-safe preprocessing and reproducibility
Project description
tidyfit
A lightweight, reproducible ML utilities toolkit focused on clean data workflows, leakage-safe preprocessing, and practical evaluation helpers.
tidyfit is designed to work in layers:
- Core (default): numpy + pandas only
- Optional extras: sklearn / matplotlib / torch when you need them
✨ Why tidyfit?
Most ML projects repeat the same boilerplate:
- splitting data safely
- tracking class imbalance
- fitting transforms on train and reusing on validation/test
- generating metrics/curve data for evaluation
- maintaining reproducibility across runs
tidyfit centralizes those patterns in a reusable package so you can move faster with fewer mistakes.
📦 Installation
Core (no sklearn)
pip install tidyfit
With optional extras
pip install "tidyfit[sklearn]"
pip install "tidyfit[viz]"
pip install "tidyfit[torch]"
Developer install
pip install -e ".[dev]"
pre-commit install
🚀 Quick start (core-only)
import pandas as pd
from tidyfit.data import stratified_split
from tidyfit.preprocessing import fit_standard_scaler, apply_standard_scaler
from tidyfit.metrics import threshold_sweep
# Example dataframe
# columns: f1, f2, y
df = pd.DataFrame(
{
"f1": [1.2, 0.5, 3.1, 2.2, 0.1, 1.7],
"f2": [10, 12, 18, 17, 9, 13],
"y": [0, 0, 1, 1, 0, 1],
}
)
(train_X, train_y), (val_X, val_y), (test_X, test_y) = stratified_split(
df, target="y", random_state=42
)
state = fit_standard_scaler(train_X, cols=["f1", "f2"])
train_X_scaled = apply_standard_scaler(train_X, state)
val_X_scaled = apply_standard_scaler(val_X, state)
# Example model scores (pretend these are from your model)
val_scores = [0.2, 0.8, 0.6]
sweep = threshold_sweep(val_y.iloc[:3], val_scores)
print(sweep.head())
🧰 CLI usage
After install, you get the tidyfit command:
tidyfit --help
Data summary
tidyfit data-summary data.csv
Imbalance report
tidyfit imbalance-report data.csv --target y
Threshold sweep
tidyfit threshold-sweep preds.csv --label-col y_true --score-col y_score
Stratified split check
tidyfit stratified-split data.csv --target y
Curve data (ROC/PR)
tidyfit curve-data preds.csv --label-col y_true --score-col y_score
Curve data + exported artifacts
tidyfit curve-data preds.csv --label-col y_true --score-col y_score --out-dir artifacts/curves
# saves:
# - roc_points.csv
# - pr_points.csv
# - roc.png (if matplotlib installed)
# - pr.png (if matplotlib installed)
Environment snapshot
tidyfit env-snapshot --out artifacts/env.json
🧩 API Overview
tidyfit.data
train_val_test_split(...)stratified_split(...)check_nulls(df)validate_schema(df, schema)distribution_summary(df, cols)imbalance_report(y)
tidyfit.preprocessing
fit_standard_scaler(df, cols)apply_standard_scaler(df, state)fit_one_hot(df, cols)apply_one_hot(df, vocab)
tidyfit.features
interaction_terms(df, cols)polynomial_features(df, cols, degree=2)drop_low_variance(df, threshold)drop_high_correlation(df, threshold)
tidyfit.metrics
classification_report_per_class(y_true, y_pred)threshold_sweep(y_true, y_score, thresholds)metric_confidence_interval(values, alpha=0.95)calibration_table(y_true, y_prob, bins=10)
tidyfit.eval_viz
confusion_matrix_data(y_true, y_pred)roc_curve_data(y_true, y_score, thresholds=None)pr_curve_data(y_true, y_score, thresholds=None)maybe_plot_curve(...)save_curve_plot(...)
tidyfit.cv
kfold_indices(...)stratified_kfold_indices(...)
tidyfit.reproducibility
set_global_seed(seed, torch=False)snapshot_environment(path)
tidyfit.model_io
save_model(obj, path, metadata=None)load_model(path)
tidyfit.tracking
log_experiment(path, payload)
tidyfit.sklearn_extra (optional: requires [sklearn])
sklearn_stratified_split(...)sklearn_stratified_cv_scores(...)
🧪 Optional dependency behavior
tidyfit is safe to use without sklearn.
If you try this module without installing the extra:
from tidyfit.sklearn_extra import sklearn_stratified_split
You will get a clear ImportError instructing you to install:
pip install "tidyfit[sklearn]"
This keeps the base install minimal and fast.
🔁 Reproducibility pattern
Recommended minimal pattern per experiment:
from tidyfit.reproducibility import set_global_seed, snapshot_environment
from tidyfit.tracking import log_experiment
set_global_seed(42)
snapshot_environment("artifacts/env.json")
log_experiment("artifacts/experiments.jsonl", {"run": "baseline", "f1": 0.84})
✅ Quality and project hygiene
- Tests:
python -m pytest -q - Lint:
python -m ruff check src tests - Format check:
python -m ruff format --check src tests - Types:
python -m mypy src/tidyfit
CI workflow: .github/workflows/ci.yml
🚢 Release workflow
Run local release checks + build:
./scripts/release.sh
This performs:
- lint/format/type/test gates
- build artifacts (
dist/) twine check
For TestPyPI publish:
- workflow:
.github/workflows/publish-testpypi.yml - required secret:
TEST_PYPI_API_TOKEN
🧾 Versioning
See CHANGELOG.md for version history (0.1.0 → 0.5.0).
📄 License
MIT — see 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 tidyfit-0.5.0.tar.gz.
File metadata
- Download URL: tidyfit-0.5.0.tar.gz
- Upload date:
- Size: 16.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8a74ac9b2c006f48e4ddc7815b2ac1b9d74d7f13b34a5bb1521283efa7e57be8
|
|
| MD5 |
bac9d9f88d92314a10d0005e06ce8591
|
|
| BLAKE2b-256 |
6eaf0d68137c046768b14f42230e7ac079364f9a24992ea9cb85293d00e843e9
|
File details
Details for the file tidyfit-0.5.0-py3-none-any.whl.
File metadata
- Download URL: tidyfit-0.5.0-py3-none-any.whl
- Upload date:
- Size: 14.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
182f2282e7d783d0881302ec30d764941e7f572757a12e584908d3a735c86f93
|
|
| MD5 |
81190391b70ce5ab682d3785e36fbdae
|
|
| BLAKE2b-256 |
08e94895b744107d0ee8b49c05f469adc589b4f5cd426b102c248f9a4c0cf656
|