dswah/pyGAM

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

mrwth opened this issue · 0 comments

mrwth commented
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?