Brinias: A symbolic regression and classification tool using Genetic Programming.
Project description
Brinias-engine: Symbolic Modeling Engine
Brinias-engine is a powerful Python library that uses Genetic Programming to automatically discover mathematical formulas that model your data. It can be used for both regression (predicting a number) and classification (predicting a category) tasks.
The key output is a simple, human-readable mathematical equation that represents the learned model.
Core Features
- Symbolic Regression & Classification: Finds the underlying formula in your data.
- Automated Feature Preprocessing: Handles numerical, categorical, and text data automatically.
- Simple API: Train a model and make predictions with just two main functions.
- Portable Models: Exports the final formula into a standalone Python file (
generated_model.py) that can be used anywhere without needing thebrinias-enginelibrary itself. - Transparent & Interpretable: The final model is a clear equation, not a black box.
What is the Output? An Example Equation
Unlike traditional "black box" models (like deep neural networks), the primary output of Brinias-engine is a mathematical formula. This formula represents the best model found to describe the relationship between your features and the target.
For example, after running on financial data, Brinias-engine might discover a formula like this:
safe_exp(protected_log(sub(sub(sub(sub(sub(sub(Close, -1.408225548256985), cos(Close)), cos(sub(Close, sin(Open)))), safe_tan(cos(Close))), cos(sub(Close, sin(Open)))), cos(sub(Close, sin(Open))))))
This raw output uses protected functions (e.g., protected_log to avoid errors) and shows the exact combination of features (Close, Open) and mathematical operations (sub, cos, safe_exp) that form the predictive model. This equation is then compiled into the final portable Python model.
1. Installation
To get started, you need git and python >= 3.7 installed on your system.
Step 1: Create a Virtual Environment (Recommended)
It is strongly recommended to create a virtual environment to keep your project dependencies isolated.
# Create the virtual environment folder
python3 -m venv .venv
# Activate it on macOS/Linux
source .venv/bin/activate
# Or activate it on Windows
# .\.venv\Scripts\activate
Step 2: Install brinias-engine
Open your terminal and run the following
```
pip install brinias-engine
```
You are now ready to use the library!
2. How to Use brinias-engine
Using brinias-engine is a simple, two-step process:
- Train a Model on your dataset.
- Make Predictions using the trained model.
The examples/ directory contains training.py, predict.py, and benchmark.py to guide you.
Step 1: Training a Model
The train_model function is the heart of the library. It takes your CSV data, finds the best formula, and saves all the resulting model files.
Example Training Script (examples/training.py)
This code trains a model using the dataeth.csv dataset.
from brinias import train_model
print("--- STARTING MODEL TRAINING ---")
# The path to the data is relative to where you run the script
# e.g., run from the project root: python examples/training.py
train_model(
csv_path="examples/dataeth.csv",
target_column="next_close",
output_dir="next_close_model", # Give the model a descriptive name
generations=120,
pop_size=100,
show_plot=True
)
print("--- TRAINING COMPLETE ---")
What Happens After Training?
A new folder named next_close_model will be created. It contains everything needed to use your model:
generated_model.py: A standalone Python script containing your model's formula. This is your portable model.equation.txt: A simple text file with the raw mathematical expression.vectorizers.pkl,original_cols.pkl, etc.: Helper files that store the data preprocessing steps.evolution_history.csv: A log of the model's performance during training.
Step 2: Making Predictions
Once the model is trained, use the make_prediction function to predict outcomes for new, unseen data.
Example Prediction Script (examples/predict.py)
from brinias import make_prediction
print("--- MAKING A NEW PREDICTION ---")
# The dictionary keys MUST match the column names from your training CSV
new_data_point = {
"timestamp": "2025-05-14",
"Open": 2679.71,
"High": 2725.99,
"Low": 2547.26,
"Close": 2609.74,
"Volume": 830047.1122,
}
# Point to the folder created during training
prediction = make_prediction(
input_data=new_data_point,
model_dir="next_close_model"
)
print("\n--- Prediction Result ---")
print(prediction)
The function will return a dictionary containing the prediction, for example: {'prediction_type': 'regression', 'predicted_value': 2650.75}.
3. Troubleshooting
ModuleNotFoundError: No module named 'brinias': Make sure you ranpip install -e .from the project's root directory and that your virtual environment is active.FileNotFoundError: [Errno 2] No such file or directory: 'my_data.csv': Check that thecsv_pathintrain_modelis correct. The path is relative to where you run thepythoncommand from.ValueError: Input data is missing expected column: 'Some_Column': The dictionary passed tomake_predictionmust contain a key for every single feature column from your original training CSV (except the target).
📊 Benchmark Results
To demonstrate the effectiveness of Brinias-engine, a fair benchmark was conducted against several standard regression models. The goal is to predict the next_close price of Ethereum.
Performance Metrics
The table below shows that Brinias achieved the lowest Mean Squared Error (MSE) and the highest R² Score, indicating the most accurate and reliable predictions on the test set.
| Model | Time (s) | MSE | R² Score |
|---|---|---|---|
| Brinias | 244.17 |
5972.45 |
0.4801 |
| Linear Regression | 0.00 |
6161.01 |
0.4637 |
| XGBoost | 0.17 |
7319.93 |
0.3628 |
| Random Forest | 0.15 |
7394.59 |
0.3563 |
Visual Comparison
The plot below visually confirms the results. The yellow line (Brinias Predictions) frequently tracks the black line (Actual Values) more closely than the other models.
Conclusion
Even on a challenging dataset, Brinias successfully discovered a symbolic formula that outperformed standard machine learning models. Its ability to find complex, non-linear relationships makes it a powerful tool for financial time-series analysis and other regression tasks where interpretability and accuracy are paramount.
To reproduce these results, run the benchmark.py script located in the examples/ directory. You will need to install xgboost via pip install xgboost.
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 brinias_engine-0.0.12.tar.gz.
File metadata
- Download URL: brinias_engine-0.0.12.tar.gz
- Upload date:
- Size: 13.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2420db96e52334a504601e3878ce7f16dd67870135ec8131e0ec59b0039b79cb
|
|
| MD5 |
c871fc4a78298c27447422f44e73c7ad
|
|
| BLAKE2b-256 |
2a8102811f7267d72de27f232f76ba675b444b04f7a1959f55e2de4c4d99ef14
|
File details
Details for the file brinias_engine-0.0.12-py3-none-any.whl.
File metadata
- Download URL: brinias_engine-0.0.12-py3-none-any.whl
- Upload date:
- Size: 11.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3bd1cb679ccd1b30318ca3bf1423ae50c60a7a39e2a48969a2d586d24b902a6
|
|
| MD5 |
9dbad5058ce29ab2f55920503afe6526
|
|
| BLAKE2b-256 |
da69a54b461b762daf845fbd16f4231f4f9ac3e0152fcb60b2e63cb6ce9b86c3
|