make_column_transformer
时间: 2023-11-20 16:06:32 浏览: 99
trasfo.rar_FEMM_transformer_transformer femm
make_column_transformer is a function provided by scikit-learn library that allows us to apply different transformers to different columns of a dataset. It is an efficient way of applying multiple transformations to different subsets of the data.
Syntax:
```
from sklearn.compose import make_column_transformer
make_column_transformer((transformer, columns), ...)
```
Example:
```
from sklearn.compose import make_column_transformer
from sklearn.preprocessing import StandardScaler, OneHotEncoder
# Define the column transformer
preprocessor = make_column_transformer(
(StandardScaler(), ['age', 'income']),
(OneHotEncoder(), ['gender', 'education'])
)
# Apply the preprocessor to the dataset
X_transformed = preprocessor.fit_transform(X)
```
In the above example, we have defined a column transformer that applies StandardScaler to the columns 'age' and 'income' and OneHotEncoder to the columns 'gender' and 'education'. We then apply the transformer to the dataset X using the fit_transform method.
阅读全文