Python framework for building robust tabular machine learning models faster and easier
Project description
EmpiricML
EmpiricML is an open-source Python framework designed to bring the rigor of empirical science to the Machine Learning development process. Are you tired of scattered Jupyter Notebooks and untracked experiments? EmpiricML provides a structured "Laboratory" environment to help you move from messy scripts to reproducible science.
The Philosophy: ML as an Empirical Science
The core idea behind EmpiricML is that building a machine learning model is an iterative, scientific process. You form a hypothesis (e.g., "Adding these specific features will decrease the error"), and you must test it in a controlled environment. EmpiricML provides that environment through the Lab class. It encapsulates everything needed for rigorous ML experimentation:
- Train and test data management
- Cross-validation strategies
- Evaluation metrics
- Standardized criteria for comparing models
Key Features
Experiment Tracking
Keep a detailed ledger of every run. EmpiricML automatically stores:
- Metric performance and overfitting percentages
- Training and inference latency
- Generated predictions for downstream analysis
Polars-Native Pipelines
Performance is at the heart of EmpiricML. Unlike scikit-learn pipelines which are NumPy-based, EmpiricML transformations utilize Polars LazyFrames. This allows for lightning-fast, memory-efficient data handling even with large datasets.
Automated Workflows
Stop writing boilerplate code for standard tasks. EmpiricML automates:
- Hyperparameter Optimization (HPO)
- Feature Importance calculation
- Automated Feature Selection
Rigorous Model Comparison
Compare experiments with statistical confidence. Define comparison criteria in your Lab class based on:
Performance Thresholds: Does Model B outperform Model A by a significant margin? Statistical Tests: Use built-in tests to ensure your improvements aren't just noise
EmpiricML can automatically update and store your "Best Model" based on these predefined rules.
Fast ML Baselines
Go from zero to a leaderboard in seconds. With just a few lines of code, you can evaluate up to 10 baseline models (including LightGBM, XGBoost, Random Forest, MLP, and more) to establish a performance floor for your project.
Early Stopping
Aborts unpromising experiments early to save compute resources.
Checkpointing
Save/Restore your Lab state to pause and resume work seamlessly.
Installation
pip install empiricml
Quick Start
1. Initialize your Laboratory
First, define the environment for your experiments. This ensures all models are evaluated on the exact same data and metrics.
import polars as pl
from empml.metrics import MAE
from empml.data import CSVDownloader
from empml.cv import KFold
from empml.lab import Lab, ComparisonCriteria
# Create the Lab
lab = Lab(
name = 'house_prices_lab',
# Data Loading
train_downloader = CSVDownloader(path='train.csv', separator=','),
test_downloader = CSVDownloader(path='test.csv', separator=','),
# Target Variable
target = 'price',
# Evaluation Protocol
metric = MAE(),
minimize = True,
cv_generator = KFold(n_splits=5, random_state=42),
# Criteria for Comparing Models
comparison_criteria = ComparisonCriteria(n_folds_threshold=1, alpha=0.05, n_iters=200)
)
2. Define a Pipeline and Run an Experiment
EmpiricML pipelines combine Feature Engineering (Transformers) and Modeling (Estimators).
from lightgbm import LGBMRegressor
from empml.pipelines import Pipeline
from empml.transformers import Log1pFeatures
from empml.wrappers import SKlearnWrapper
# Define features to use
features = ['sqft_living', 'sqft_lot', 'bedrooms', 'bathrooms']
# Create a pipeline
pipe = Pipeline(
steps = [
# Feature Engineering: Apply Log1p to numerical features
('log_scale', Log1pFeatures(features=features, suffix='')),
# Modeling: Wrap sklearn-compatible estimators
('model', SKlearnWrapper(
estimator=LGBMRegressor(verbose=-1),
features=features,
target='price'
))
],
name = 'LGBM_Optimized',
description = 'LightGBM regressor with log-transformed features.'
)
# Run the experiment in the Lab
lab.run_experiment(pipeline=pipe)
3. Hyperparameter Optimization
EmpiricML simplifies hyperparameter tuning with built-in Grid and Random Search capabilities. This allows you to systematically explore different model configurations.
from sklearn.tree import DecisionTreeRegressor
# Define the parameter grid
params = {
'max_depth': [3, 5, 10],
'min_samples_split': [2, 5, 10]
}
# Run Hyperparameter Optimization
# Note: Pass the estimator class (not an instance) to the hpo method
best_result_row = lab.hpo(
features=features,
params_list=params,
estimator=DecisionTreeRegressor,
search_type='grid', # Options: 'grid' or 'random'
verbose=True
)
4. Accessing Experiment Results
All experiment tracking data, including results from single runs and HPO, is stored in the lab.results DataFrame. This Polars DataFrame contains metrics, execution times, and metadata for every experiment run in the session.
# View all experiment results as a Polars DataFrame
lab.results
# Get the best performing experiment stats
lab.show_best_score()
Project Structure
The library is organized into logical modules found in src/empml:
lab: The coreLabclass management.pipeline: Scikit-learn style pipelines compatible with Polars.wrappers: Wrappers for ML algorithms (XGBoost, LightGBM, CatBoost, Sklearn, Pytorch).transformers: Feature engineering blocks.metrics: Performance metrics.data: Tools for handling data loading and downloads.cv: Cross-validation splitters.
Contributing
Contributions are welcome! Please check out the issues or submit a PR.
- Fork the repository
- Create your feature branch (
git checkout -b feature/new-feature) - Commit your changes (
git commit -m 'Add some new feature') - Push to the branch (
git push origin feature/new-feature) - Open a Pull Request
Citation
If you use EmpiricML in your research, please cite:
@software{EmpiricML,
title={EmpiricML: A Python framework for building robust Machine Learning models on tabular data faster and easier},
author={Pasquale Trani},
year={2026},
url={https://github.com/PasqualeTrani/EmpiricML}
}
License
Distributed under the MIT License. See LICENSE for more information.
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 empiricml-0.1.0.tar.gz.
File metadata
- Download URL: empiricml-0.1.0.tar.gz
- Upload date:
- Size: 36.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d989cf892c2c7db88a22597b6f7e2ad6b907e7316b3a231f390a4d433c566542
|
|
| MD5 |
38c03d76b3f5b41300dbdb2c269f505a
|
|
| BLAKE2b-256 |
b3df55aa77220d90bc27c3b1d8f6740bc5ef71c2e5e6b9b0dc348fa447ae8a3e
|
File details
Details for the file empiricml-0.1.0-py3-none-any.whl.
File metadata
- Download URL: empiricml-0.1.0-py3-none-any.whl
- Upload date:
- Size: 40.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
73fa4edd22039b3017370540739a0424ea57ed76f5841324fac7260cabbd0bdb
|
|
| MD5 |
cdd9527ae94ca3b9abcc0260dce36479
|
|
| BLAKE2b-256 |
f75862a55426c690cae21b062eed55b6e34c8e27a25777ea62b70a8038bb668d
|