Complete the code to import the correct class for transforming columns.
from sklearn.compose import [1]
The ColumnTransformer class is used to apply different transformations to different columns.
Complete the code to create a ColumnTransformer that applies OneHotEncoder to categorical columns.
from sklearn.compose import ColumnTransformer from sklearn.preprocessing import OneHotEncoder ct = ColumnTransformer(transformers=[('cat', [1](), ['color', 'type'])], remainder='passthrough')
OneHotEncoder is used to convert categorical columns into one-hot numeric arrays.
Fix the error in the code to apply StandardScaler to numeric columns.
from sklearn.compose import ColumnTransformer from sklearn.preprocessing import StandardScaler ct = ColumnTransformer(transformers=[('num', [1](), ['age', 'income'])], remainder='passthrough')
StandardScaler scales numeric features to have mean 0 and variance 1.
Fill both blanks to create a ColumnTransformer that imputes missing values in numeric columns and encodes categorical columns.
from sklearn.compose import ColumnTransformer from sklearn.impute import [1] from sklearn.preprocessing import [2] ct = ColumnTransformer(transformers=[('num', [1](), ['age', 'income']), ('cat', [2](), ['gender', 'city'])], remainder='passthrough')
SimpleImputer fills missing values, and OneHotEncoder encodes categorical features.
Fill all three blanks to create a pipeline that preprocesses numeric and categorical data, then fits a logistic regression model.
from sklearn.compose import ColumnTransformer from sklearn.pipeline import Pipeline from sklearn.linear_model import [1] from sklearn.impute import [2] from sklearn.preprocessing import [3], StandardScaler numeric_transformer = Pipeline(steps=[('imputer', [2]()), ('scaler', StandardScaler())]) categorical_transformer = Pipeline(steps=[('encoder', [3](handle_unknown='ignore'))]) ct = ColumnTransformer(transformers=[('num', numeric_transformer, ['age', 'income']), ('cat', categorical_transformer, ['gender', 'city'])]) model = Pipeline(steps=[('preprocessor', ct), ('classifier', [1]())])
This pipeline imputes missing numeric values with SimpleImputer, encodes categorical data with OneHotEncoder, and fits a LogisticRegression model.