Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Symbolic model does not evaluate to the same values as predict #289

Open
folivetti opened this issue Nov 21, 2022 · 2 comments
Open

Symbolic model does not evaluate to the same values as predict #289

folivetti opened this issue Nov 21, 2022 · 2 comments

Comments

@folivetti
Copy link

Using the same dataset from the other issue (I can reupload again if you want), running the following code:

from feat import FeatRegressor

def standardNotation(expr):
    expr = (expr.replace("X0", "x0")
            .replace("X1", "x1")
            .replace("X2", "x2")
            .replace("_", "")
            .replace("+-", "-")
            .replace("--", "+")
            .replace("^", "**")
            )
    expr = re.sub(r"/(-\d+\.\d+)", r"/(\1)", expr)
    return re.sub(r"\*(-\d+\.\d+)", r"*(\1)", expr)

def protected(expr):
    return expr.replace("log", "plog")
def model(est):
    return est.get_eqn()

est = FeatRegressor(
                    pop_size=500,
                    gens=2,
                    backprop=False,
                    iters=1,
                    max_depth=2,
                    functions="+,-,*,/", # remove exp, log for kotanchek
                    verbosity=0,
                    random_state=55
                   )

est.fit(x,y)
eq = protected(standardNotation(model(est))) # normalizes the expression
yhat = eval(eq) # evaluates the symbolic expression
yhat2 = FEAT.est.predict(x) # the same but using the internal method
print(np.square(yhat-yhat2).mean())

I get: 276.03250450032573 where I should get something close to 0. I'm not really sure if it is related to the other issue or if it's an unrelated issue.

@lacava
Copy link
Member

lacava commented Dec 14, 2022

I think this has to do with the coefficient values being incorrect during normalization, as in this issue #286

can you try setting normalize=False in FeatRegressor?

@folivetti
Copy link
Author

Same problem! I had to change the seed to 59 test with normalize=False because with seed 55 and without normalization, it returned an invalid expression as in that other issue I opened.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants