Конвейер sklearn – как применить преобразование к НЕКОТОРЫМ преобразованным столбцам?Python

Программы на Python
Гость
Конвейер sklearn – как применить преобразование к НЕКОТОРЫМ преобразованным столбцам?

Сообщение Гость »


suppose I have two numerical and two categorical transformations, and apply these transformations on distinct columns num_col1, num_col2, cat_col1 and cat_col2.

Код: Выделить всё

num1_pre = Pipeline([ ... ])
num2_pre = Pipeline([ ... ])

cat1_pre = Pipeline([ ... ])
cat2_pre = Pipeline([ ... ])

preprocessor = ColumnTransformer([
("num1_pre", num1_pre, num_col1),
("num2_pre", num2_pre, num_col2),
("cat1_pre", cat1_pre, cat_col1),
("cat2_pre", cat2_pre, cat_col2)
])
Suppose now after the transformation I wish to use

Код: Выделить всё

PolynomialFeatures()
on the transformed num_col1 and num_col2 combined. How can I proceed? I know how this can be done if there were no transformation on the categoricals by something like

Код: Выделить всё

preprocessing = ColumnTransformer([
('num1_pre', num1_pre, num_col1),
('num2_pre', num2_pre, num_col2)
])

full_pipeline = Pipeline([
('preprocessing', preprocessing),
('poly', PolynomialFeatures())
])

model_pipeline = Pipeline([
('full_preprocessing', full_pipeline),
('model', LinearRegression())
])
The problem is I can't figure out how to do this with the presence of the categorical transformation. Thanks!


Источник: https://stackoverflow.com/questions/781 ... med-column

Вернуться в «Python»