PySR / example.py
MilesCranmer's picture
Rename loss => elementwise_loss and full_objective => loss_function
d16abb4 unverified
raw
history blame contribute delete
637 Bytes
import numpy as np
X = 2 * np.random.randn(100, 5)
y = 2.5382 * np.cos(X[:, 3]) + X[:, 0] ** 2 - 0.5
from pysr import PySRRegressor
model = PySRRegressor(
model_selection="best", # Result is mix of simplicity+accuracy
niterations=40,
binary_operators=["+", "*"],
unary_operators=[
"cos",
"exp",
"sin",
"inv(x) = 1/x",
# ^ Custom operator (julia syntax)
],
extra_sympy_mappings={"inv": lambda x: 1 / x},
# ^ Define operator for SymPy as well
elementwise_loss="loss(x, y) = (x - y)^2",
# ^ Custom loss function (julia syntax)
)
model.fit(X, y)
print(model)