MLA-C01 Practice Question 12: Categorical Encoding Nominal
AWS Certified Machine Learning Engineer – Associate (MLA-C01) · Test 2 · question 2 of 10
An ML engineer is preparing features for a linear model that predicts the value of an online order. One input column, payment_method, contains one of four strings: card, wallet, bank_transfer, or cash. The categories have no natural order, and the linear model accepts only numeric inputs.
How should the engineer encode this column?
Show answer and explanation
Answer:
payment_method is a *nominal* categorical feature: its categories have no inherent order. One-hot encoding turns it into a set of binary indicator columns, one per category, so the linear model can learn a separate weight for each payment method without assuming anything about how they relate. With only four categories, the extra columns are no burden. SageMaker Data Wrangler and Glue DataBrew both provide one-hot encoding as a built-in transform.
Option A is the right tool for *ordinal* categories, such as education level, where the order is real. Applied to a nominal column it tells the linear model that cash (3) is "three times" wallet (1) and that the categories lie on a line, and the model will fit a single slope across that invented scale.
Option B discards a potentially useful signal for no reason; converting categories to numbers is exactly what encoding is for.
Option C describes target encoding done wrong. Computing the per-category mean of the label over the full dataset before splitting leaks validation labels into the training features, and for four well-populated categories it adds risk without adding value over one-hot encoding.
Reference: Transform Data (Encode Categorical)