Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete the code to convert the 'color' column to categorical type.
ML Python
df['color'] = df['color'].[1]()
Drag options to blanks, or click blank then click option'
Attempts:
3 left
2fill in blank
mediumComplete the code to create one-hot encoded columns for the 'color' categorical variable.
ML Python
encoded_df = pd.get_dummies(df['color'], [1]=False)
Drag options to blanks, or click blank then click option'
Attempts:
3 left
3fill in blank
hardFix the error in encoding the 'size' column using LabelEncoder.
ML Python
from sklearn.preprocessing import LabelEncoder le = LabelEncoder() df['size_encoded'] = le.[1](df['size'])
Drag options to blanks, or click blank then click option'
Attempts:
3 left
4fill in blank
hardFill both blanks to create a dictionary mapping categories to numbers using pandas.
ML Python
mapping = {cat: num for num, cat in enumerate(df['category'].[1]())}
encoded = df['category'].[2](mapping) Drag options to blanks, or click blank then click option'
Attempts:
3 left
5fill in blank
hardFill all three blanks to create a pipeline that imputes missing values, encodes categories, and fits a model.
ML Python
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]()) ])
Drag options to blanks, or click blank then click option'
Attempts:
3 left