Symbolic Regression with SPINEX algorithm
Project description
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()
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
spinex_sr-0.1.1.tar.gz
(18.5 kB
view details)
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
spinex_sr-0.1.1-py3-none-any.whl
(16.8 kB
view details)
File details
Details for the file spinex_sr-0.1.1.tar.gz.
File metadata
- Download URL: spinex_sr-0.1.1.tar.gz
- Upload date:
- Size: 18.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bccbaabc4917f82187c839f3fcd6e687bdeda26ea6aa6bdddcecd63962cc5239
|
|
| MD5 |
1abd39e680f7c621b952967d918d4777
|
|
| BLAKE2b-256 |
7f8f3bb7074dd786ad4b5b5519fffb0afa70947b3de650b8918ef4a98a11a7b7
|
File details
Details for the file spinex_sr-0.1.1-py3-none-any.whl.
File metadata
- Download URL: spinex_sr-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
59b094592fe0890ea2800344582da4b019fb49806538ae7af94cbcf2ddcec346
|
|
| MD5 |
189a36466c01cf283365db35c753662e
|
|
| BLAKE2b-256 |
9e6c1fe4f07931ea7720b36fb2407cc8a97e2735133bf783caa45d747f13003f
|