In the documentation of TransformedTargetRegressor, it is mentioned that the parameter func
needs to return a 2-dimensional array. Should it not be a 1-dimensional array instead? The target y mostly has the shape (n_samples,) which is 1-dimensional.
The below code, where target y and the output of func
is 1-dimensional, runs properly -
exponentiate = lambda x: np.exp(x)
naturalLog = lambda x: np.log(x)
loglinreg = compose.TransformedTargetRegressor(regressor=linear_model.LinearRegression(),func=naturalLog,inverse_func=exponentiate)
loglinreg.fit(X_train,yCO_train)
loglinreg.score(X_train,yCO_train)