A modular optimization and machine learning workflow framework for hyperparameter tuning and performance benchmarking across diverse datasets.
Project description
OptiFlowX
OptiFlowX is an open-source framework for hyperparameter optimization using combinatorial and metaheuristic algorithms. It enables systematic exploration of search spaces for machine learning models using advanced stochastic and hybrid optimization techniques.
🔍 Overview
Machine learning models rely on carefully tuned hyperparameters. Conventional methods such as grid or simple random search become inefficient for discrete, mixed or high-dimensional search spaces.
OptiFlowX is a modular framework for hyperparameter and configuration optimization that brings together combinatorial and metaheuristic algorithms so you can search complex spaces with a consistent, extensible API.
Key capabilities include:
- Flexible support for classification and regression tasks via a
task_typeparameter. - First-class support for user-provided
custom_metric(y_true, y_pred)callables (the framework will use them for cross-validation and accept them in parallel workers, with adillfallback for non-pickleable callables). - Unified scoring interface: built-in metrics (accuracy, f1, mse, rmse, mae, r2) are normalized so optimizers can always maximize a single numeric score.
⚙️ Key Features
- Unified interface for multiple optimization algorithms.
- Works with discrete, categorical, and continuous parameter spaces.
- Includes multiple strategies:
- Genetic Algorithm (GA)
- Particle Swarm Optimization (PSO)
- Bayesian Optimization
- Tree-structured Parzen Estimator (TPE)
- Random Search
- Simulated Annealing
- Scalable, parallel execution support.
- Compatible with any ML framework (scikit-learn, PyTorch, TensorFlow, etc.).
Additional highlights:
- Custom metric support: pass a callable
def my_metric(y_true, y_pred) -> floatand the engine will use it for evaluation (supports multiprocessing via a serialization fallback). - Regression-ready: built-in regression metrics (
mse,rmse,mae,r2) are provided and normalized so the optimizer maximizes performance. - Consistent return format: optimizers return
(best_params, best_score)so results are easy to consume programmatically.
⚗️ Installation
pip install optiflowx
or from source:
git clone https://github.com/Faycal214/optiflowx.git
cd optiflowx
pip install -e .
🧠 Example Usage
from sklearn.datasets import make_classification, make_regression
from optiflowx.optimizers.genetic import GeneticOptimizer
from optiflowx.optimizers.pso import PSOOptimizer
from optiflowx.models.configs.random_forest_config import RandomForestConfig
# Example 1 — classification with a built-in metric
X, y = make_classification(n_samples=200, n_features=12, random_state=0)
cfg = RandomForestConfig()
search_space = cfg.build_search_space()
model_wrapper = cfg.get_wrapper(task_type="classification")
opt = PSOOptimizer(
search_space=search_space,
metric="accuracy",
model_class=model_wrapper.model_class,
X=X,
y=y,
n_particles=12,
)
best_params, best_score = opt.run(max_iters=5)
print("Classification result:", best_score, best_params)
# Example 2 — regression with built-in metric
Xr, yr = make_regression(n_samples=200, n_features=8, noise=0.1, random_state=1)
cfg = RandomForestConfig()
reg_wrapper = cfg.get_wrapper(task_type="regression")
optr = GeneticOptimizer(
search_space=search_space,
metric="mse", # mse is negated internally so higher is better
model_class=reg_wrapper.model_class,
X=Xr,
y=yr,
population=20,
)
best_params_r, best_score_r = optr.run(max_iters=5)
print("Regression result:", best_score_r, best_params_r)
# Example 3 — custom metric callable
def my_custom_metric(y_true, y_pred):
"""User-defined metric: return any float (higher is better)."""
# e.g., negative mean absolute error (so higher is better)
from sklearn.metrics import mean_absolute_error
return -float(mean_absolute_error(y_true, y_pred))
opt_custom = PSOOptimizer(
search_space=search_space,
metric="accuracy",
custom_metric=my_custom_metric,
model_class=model_wrapper.model_class,
X=X,
y=y,
n_particles=8,
)
best_params_c, best_score_c = opt_custom.run(max_iters=4)
print("Custom metric result:", best_score_c, best_params_c)
🧪 Testing
pytest -v --maxfail=1 --disable-warnings
🧩 Optional dependency: dill
If you plan to pass non-top-level (non-pickleable) custom_metric callables
to optimizers while using multiprocessing, the project can optionally use
dill to serialize those callables. If dill is not installed, custom
metrics must be pickleable (e.g., top-level functions).
Install dill in your environment with:
pip install dill
The framework will automatically attempt to use dill when necessary; if it
is not present and a non-pickleable callable is provided, an error will be
raised with guidance to install dill or provide a pickleable metric.
📚 Citation
@software{optiflowx,
author = {Faycal, Alikacem},
title = {OptiFlowX: Combinatorial Hyperparameter Optimization Framework},
year = {2025},
url = {https://github.com/Faycal214/optiflowx}
}
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 optiflowx-0.0.6.tar.gz.
File metadata
- Download URL: optiflowx-0.0.6.tar.gz
- Upload date:
- Size: 96.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.1 cpython/3.12.3 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7d54f7feff3399106931492611efaf55da45dcdaa1481f2d72b0aa8ecd17b09a
|
|
| MD5 |
aae3e7bccdc3388440e1a47dd9ce6509
|
|
| BLAKE2b-256 |
819a02dd1f45158d39d4d71e279b7972e443bf3d1ca53b593bedff049b84b7c6
|
File details
Details for the file optiflowx-0.0.6-py3-none-any.whl.
File metadata
- Download URL: optiflowx-0.0.6-py3-none-any.whl
- Upload date:
- Size: 50.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: Hatch/1.16.1 cpython/3.12.3 HTTPX/0.28.1
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3a919dec00bfbe511f93197daa3153c1bf7b3219d4df0c6bc1f64fa0bccca4aa
|
|
| MD5 |
bd9226cdf13633f27214ac7f8d8ba942
|
|
| BLAKE2b-256 |
f61d430e0746b45f1135329d9c5318864d70b3c9f7a62545a7e96dbcdfdca31e
|