Skip to content

PySR

flowcean.pysr provides symbolic regression through PySR. Install the pysr extra as described in installation.

Configure a PySRRegressor, wrap it in PySRLearner, and call learn(inputs, outputs) with lazy Polars frames. The inputs contain the explanatory variables and the outputs contain one target column. The returned PySRModel predicts that target and exposes the learned equation through flow_summary().

from pysr import PySRRegressor
from flowcean.pysr import PySRLearner

learner = PySRLearner(PySRRegressor(niterations=10))
model = learner.learn(inputs, outputs)
predictions = model.predict(inputs).collect()
print(model.flow_summary())

For HyDRA discovery, supply a factory that creates a fresh learner and regressor for each fit:

regressor_factory = lambda: PySRLearner(PySRRegressor(niterations=10))

pysr

Classes

PySRLearner

PySRLearner(model: PySRRegressor)

Bases: SupervisedLearner

Fit a symbolic equation for one target from a batch of observations.

Parameters:

Name Type Description Default
model PySRRegressor

Configured PySR regressor used by learn.

required

For HyDRA discovery, supply a factory that creates a fresh PySRLearner and PySRRegressor for each fit.

Attributes
model instance-attribute
model = model
Methods:
learn
learn(inputs: LazyFrame, outputs: LazyFrame) -> Model

Fit the configured regressor and return its prediction model.

Parameters:

Name Type Description Default
inputs LazyFrame

Lazy Polars frame of explanatory variables.

required
outputs LazyFrame

Lazy Polars frame with one target column and rows aligned with inputs.

required

Returns:

Type Description
Model

A PySRModel whose predictions use the target column name.

PySRModel

PySRModel(model: PySRRegressor, output_column: str)

Bases: Model

Attributes
model instance-attribute
model = model
output_column instance-attribute
output_column = output_column
Methods:
flow_summary
flow_summary() -> str

Functions: