Databricks Machine Learning Associate Question 193
Single answerYou are working on a machine learning project in Databricks where you need to preprocess a dataset containing categorical features for use in a regression model. One of the categorical columns, 'Product_Type', contains three unique values: ['Electronics', 'Clothing', 'Furniture']. You decide to use one-hot encoding to transform this column. What will be the output when one-hot encoding is applied to the 'Product_Type' column?
- A
A new column is created with numerical values representing 'Product_Type' in ascending order (e.g., 0 for 'Clothing', 1 for 'Electronics', 2 for 'Furniture').
- B
Three new columns are added to the dataset, one for each unique value in 'Product_Type', containing binary indicators (0 or 1).
- C
The 'Product_Type' column is replaced by a single column containing binary values (0 or 1).
- D
Three new columns are added to the dataset, one for each unique value in 'Product_Type', containing numerical values representing the frequency of each category.
Show answer and explanation
Correct answer: B
Explanation
One-hot encoding is a preprocessing technique used to convert categorical features into a format suitable for machine learning models. In this case, the 'Product_Type' column has three unique categories. One-hot encoding will create three new binary columns, one for each category ('Electronics', 'Clothing', 'Furniture'), with 1 indicating the presence of the category and 0 otherwise. This method ensures that the model does not assume any ordinal relationship between the categories.
- A. Incorrect.
This describes label encoding, not one-hot encoding. Label encoding assigns numerical values to categories but does not create separate binary columns for each unique category.
- B. Correct.
This is the correct answer. One-hot encoding creates a new binary column for each unique category in the categorical feature, where the value is 1 if the row belongs to that category and 0 otherwise.
- C. Incorrect.
This is incorrect. One-hot encoding does not replace the categorical column with a single binary column; it creates multiple binary columns for each unique category.
- D. Incorrect.
This is incorrect. One-hot encoding does not involve frequencies; it only creates binary indicators for each unique category.