Databricks Machine Learning Associate Question 192
Single answerYou are training a machine learning model in Databricks using a dataset that contains a categorical feature named 'Region' with values ['North', 'South', 'East', 'West']. You decide to use one-hot encoding to preprocess this feature. Which of the following statements about the one-hot encoding process is correct?
- A
One-hot encoding will create a new feature for each unique value in 'Region', and each row will have a 1 in the column corresponding to its original value and 0 elsewhere.
- B
One-hot encoding will replace the 'Region' column with a single numerical column, where each unique value is mapped to a unique integer.
- C
One-hot encoding can only be applied to numerical features and is not suitable for categorical data like 'Region'.
- D
One-hot encoding will create a single binary column to represent whether 'Region' belongs to a specific category or not.
Show answer and explanation
Correct answer: A
Explanation
One-hot encoding is a preprocessing technique that converts categorical features into a series of binary columns representing the presence of each category. This is essential for many machine learning algorithms that require numerical input. In this scenario, the 'Region' column will be expanded into four binary columns, one for each unique value ('North', 'South', 'East', 'West'). Each row will have a 1 in the column corresponding to its original category and 0 in all others.
- A. Correct.
Correct. One-hot encoding creates a binary column for each unique category in the feature, and the value for each row is 1 in the column corresponding to its category and 0 in all other columns.
- B. Incorrect.
Incorrect. This describes label encoding, not one-hot encoding. Label encoding assigns a unique integer to each category but does not create multiple binary columns.
- C. Incorrect.
Incorrect. One-hot encoding is specifically designed for categorical features and is commonly used to preprocess such data.
- D. Incorrect.
Incorrect. One-hot encoding does not create a single binary column; it creates multiple binary columns, one for each category in the original feature.