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.0.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.0.1-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: brinias_engine-0.0.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.0.1.tar.gz
Algorithm Hash digest
SHA256 bf0d326f83896f4b5b0774576dc1667242f568dff45c1e7236facce8070c78c5
MD5 826177a7935a4526cca57fb13b5d7258
BLAKE2b-256 f326cab880378e47166f3a99c128821ffdb8e3a9549e9978fced7d855662991d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: brinias_engine-0.0.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.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 346928d6ec382e943e527d8e066194cb2d3d4c42aeffd7c11742141721bd493e
MD5 24aa4b47dcbf1054e54f3c07e169de4d
BLAKE2b-256 aae24221a53924f8a6c758c0081b7dc8c6972f2c53579144f2260165c4254211

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