I'd like to use both Pipeline and TransformedTargetRegressor to handle all the scaling (on data and target) : is this possible to mix Pipeline and TransformedTargetRegressor ? How to get results out of TransformedTargetRegressor ?
$ cat test_ttr.py
#!/usr/bin/python
# -*- coding: UTF-8 -*-
from sklearn.datasets import make_regression
from sklearn import preprocessing
from sklearn.model_selection import train_test_split
from sklearn import linear_model
from sklearn.pipeline import Pipeline
from sklearn.compose import TransformedTargetRegressor
def main():
x, y = make_regression()
x_train, x_test, y_train, y_test = train_test_split(x, y, test_size=0.2)
model = linear_model.Ridge(alpha=1)
pipe = Pipeline([('scale', preprocessing.StandardScaler()), ('model', model)])
treg = TransformedTargetRegressor(regressor=pipe, transformer=preprocessing.MinMaxScaler())
treg.fit(x_train, y_train)
print(pipe.get_params()['model__alpha']) # OK !
print(treg.get_params()['regressor__model__coef']) # KO ?!
if __name__ == '__main__':
main()
But can't get results (coefs for instance) out of TransformedTargetRegressor
1
Traceback (most recent call last):
File ".\test_ttr.py", line 26, in <module>
main()
File ".\test_ttr.py", line 23, in main
print(treg.get_params()['regressor__model__coef']) # KO ?!
TypeError: 'TransformedTargetRegressor' object is not subscriptable
from sklearn : scaling x (data) and y (target) using both Pipeline and TransformedTargetRegressor
No comments:
Post a Comment