SPINEX Symbolic Regression
A Python implementation of symbolic regression from the SPINEX family.
Installation
pip install spinex-sr
Quick Start
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from spinex_sr import SPINEX_SymbolicRegression
if __name__ == "__main__":
# Generate sample data for the multi-variable problem
np.random.seed(42)
X = np.linspace(0, 10, 100)
Y = np.linspace(5, 15, 100)
Z = np.linspace(5, 15, 100)
# Define the actual function with multiple variables
def actual_function_multi(X, Z):
return X + Y + 3 * Z
y_multi = actual_function_multi(X, Z)
df_multi = pd.DataFrame({'X': X, 'Y': Y, 'Z': Z})
# Create an instance of Symbolic_SPINEX for the multi-variable problem
symbolic_spinex_multi = SPINEX_SymbolicRegression(
df_multi, y_multi,
actual_function="y = 2 * X**2 + 3 * X + 5",
max_depth=3,
population_size=25,
generations=55,
explainability_level='none',
plot_results=True,
early_stopping_metric='r2',
early_stopping_value=0.79,
patience=3,
n_jobs=-1,
last_resort=True, # Enable last resort mode
force_all_variables=False
)
symbolic_spinex_multi.initialize_population()
best_expression_multi = symbolic_spinex_multi.evolve()
symbolic_spinex_multi.best_expression = best_expression_multi
# Call explain() to get the advanced explanation and plot for multi-variable
symbolic_spinex_multi.explain()
# Generate sample data for the single-variable problem
X_single = np.linspace(0, 10, 100)
# Define the actual function for the single-variable problem
def actual_function_single(X):
return 2 * X**2 + 3 * X + 5
y_single = actual_function_single(X_single)
df_single = pd.DataFrame({'X': X_single})
# Create an instance of Symbolic_SPINEX for the single-variable problem
symbolic_spinex_single = SPINEX_SymbolicRegression(
df_single, y_single,
actual_function="y = 2 * X**2 + 3 * X + 5",
max_depth=3,
population_size=50,
generations=50,
explainability_level='advanced',
plot_results=True,
early_stopping_metric='mse',
early_stopping_value=200,
patience=3,
n_jobs=-1,
dynamic_elite=True,
last_resort=True, # Enable last resort mode
force_all_variables=True
)
symbolic_spinex_single.initialize_population()
best_expression_single = symbolic_spinex_single.evolve()
symbolic_spinex_single.best_expression = best_expression_single
# Call explain() to get the advanced explanation and plot for single-variable
symbolic_spinex_single.explain()
plt.show()
Release files for spinex-sr 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| spinex_sr-0.1.1.tar.gz | 18.5 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| spinex_sr-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 35.3 kB
Release files / spinex_sr-0.1.1.tar.gz
| Download URL | spinex_sr-0.1.1.tar.gz |
|---|---|
| Size | 18.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
bccbaabc4917f82187c839f3fcd6e687bdeda26ea6aa6bdddcecd63962cc5239
|
|
BLAKE2b-256 checksum How to use checksums |
7f8f3bb7074dd786ad4b5b5519fffb0afa70947b3de650b8918ef4a98a11a7b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|
Release files / spinex_sr-0.1.1-py3-none-any.whl
| Download URL | spinex_sr-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
59b094592fe0890ea2800344582da4b019fb49806538ae7af94cbcf2ddcec346
|
|
BLAKE2b-256 checksum How to use checksums |
9e6c1fe4f07931ea7720b36fb2407cc8a97e2735133bf783caa45d747f13003f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.12.7
|