Skip to main content

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 the brinias-engine library 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:

  1. Train a Model on your dataset.
  2. 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 ran pip 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 the csv_path in train_model is correct. The path is relative to where you run the python command from.
  • ValueError: Input data is missing expected column: 'Some_Column': The dictionary passed to make_prediction must 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.

Benchmark Plot

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

brinias_engine-0.1.1.tar.gz (13.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

brinias_engine-0.1.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file brinias_engine-0.1.1.tar.gz.

File metadata

  • Download URL: brinias_engine-0.1.1.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

Hashes for brinias_engine-0.1.1.tar.gz
Algorithm Hash digest
SHA256 2f8b557be4bd63d89ce7f955d66ec8df0319e7bf65f979bb37a56ee43473eb4e
MD5 a1b428b9fd8d8d3a0a0a3846295ce904
BLAKE2b-256 375e808df44ca086295860b581dba473e891aaf24e0b75636c06256f1ffd7048

See more details on using hashes here.

File details

Details for the file brinias_engine-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: brinias_engine-0.1.1-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

Hashes for brinias_engine-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f8beae355b90527b217cd71505b630b2bcbe116fe1b6ad2c444b478ce872fd0
MD5 75aa740d1c0cf7434f226844c515a5af
BLAKE2b-256 ebb28b4e097bd89bf24e306911c585a6cc9a82f99eebb6ab2f4d06d016a1ca7f

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page