What does one-hot encoding do to a categorical feature such as color with the values red, green and blue?
Show the answer and explanation
Correct answer: C, It creates one binary column per color, set to 1 for the row's own color and to 0 in the remaining columns.
Explanation Encoding
One-hot encoding turns a categorical feature with k categories into k binary indicator columns (color_red, color_green, color_blue). For a known category exactly one of them is 1 and the rest are 0, so no order or distance between categories is implied.
Why the other descriptions are different encoders:
- Integer codes in a single column are label / ordinal encoding, which implies an order.
- Replacing a category by its mean target is target encoding.
- Replacing a category by its share of rows is frequency (count) encoding.
| color | color_red | color_green | color_blue |
|---|---|---|---|
| green | 0 | 1 | 0 |
For a linear model with an intercept, keeping all k columns makes them perfectly collinear (they always sum to 1), so one column is usually dropped (k − 1 dummies).
Interview tip: mention the dummy variable trap and that one-hot becomes impractical when the feature has thousands of categories.