Complete the code to convert the 'color' column to categorical type.
df['color'] = df['color'].[1]()
Using astype('category') converts the column to categorical type, which is efficient for categorical data.
Complete the code to create one-hot encoded columns for the 'color' categorical variable.
encoded_df = pd.get_dummies(df['color'], [1]=False)
The drop_first=True option avoids multicollinearity by dropping the first category.
Fix the error in encoding the 'size' column using LabelEncoder.
from sklearn.preprocessing import LabelEncoder le = LabelEncoder() df['size_encoded'] = le.[1](df['size'])
fit_transform fits the encoder and transforms the data in one step, which is needed here.
Fill both blanks to create a dictionary mapping categories to numbers using pandas.
mapping = {cat: num for num, cat in enumerate(df['category'].[1]())}
encoded = df['category'].[2](mapping)unique() gets unique categories, and map() applies the mapping to encode the column.
Fill all three blanks to create a pipeline that imputes missing values, encodes categories, and fits a model.
from sklearn.pipeline import Pipeline from sklearn.impute import SimpleImputer from sklearn.preprocessing import OneHotEncoder pipeline = Pipeline([ ('imputer', SimpleImputer(strategy=[1])), ('encoder', OneHotEncoder(handle_unknown=[2])), ('model', [3]()) ])
Use 'mean' strategy to fill missing numeric values, 'ignore' to handle unknown categories gracefully, and LogisticRegression as the model.
