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

Specifying terms in LinearGAM is incompatible with sklearn.compose.TransformedTargetRegressor (bug) #333

Open
mrwth opened this issue Apr 24, 2023 · 0 comments

Comments

@mrwth
Copy link

mrwth commented Apr 24, 2023

from sklearn.compose import TransformedTargetRegressor

def exp_model(model):
    return TransformedTargetRegressor(regressor=model, func=np.exp, inverse_func=np.log)

X = np.linspace(0,1,100).reshape(-1, 1)
y = np.linspace(0, 1, 100)

model = exp_model(LinearGAM(s(0)))
model.fit(X, y)
y_pred = model.predict(X)

plt.plot(y, y_pred)

draws, incorrectly, a horizontal line, while the supposedly equivalent

from sklearn.compose import TransformedTargetRegressor

def exp_model(model):
    return TransformedTargetRegressor(regressor=model, func=np.exp, inverse_func=np.log)

X = np.linspace(0,1,100).reshape(-1, 1)
y = np.linspace(0, 1, 100)

model = exp_model(LinearGAM())
model.fit(X, y)
y_pred = model.predict(X)

plt.plot(y, y_pred)

(differing only by deleting s(0)) draws, correctly, the diagonal.

Is there any way out?

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

1 participant