Skip to content

Revisiting Symbolic regression with "conditional constants" (#521) #904

Answered by MilesCranmer
debraaudus asked this question in Q&A
Discussion options

You must be logged in to vote

The latest PySR which came out some time after those previous responses has a feature dedicated for this! Check out TemplateExpressionSpec, specifically with the parameters option: https://ai.damtp.cam.ac.uk/pysr/examples/#11-expression-specifications:

spec = TemplateExpressionSpec(
    expressions=["f", "g"],
    variable_names=["x1", "x2", "class"],
    parameters={"p1": 3, "p2": 3},
    combine="p1[class] * sin(f(x1, x2)) + p2[class]",
)

model = PySRRegressor(expression_spec=spec)
model.fit(X, y)

In this example, the third column of X is the categorical feature, and the first two are regular features.

We also prescribe the specific form they are used. But you can also just write down

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
3 replies
@debraaudus
Comment options

@MilesCranmer
Comment options

@debraaudus
Comment options

Answer selected by debraaudus
Comment options

You must be logged in to vote
1 reply
@MilesCranmer
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants