Skip to content

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

@folivetti

Description

@folivetti

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions