Databricks Machine Learning Associate Question 191
Single answerYou are working on a machine learning project in Databricks and need to preprocess a categorical feature 'Color' with values ['Red', 'Blue', 'Green', 'Red']. You decide to use one-hot encoding. Which of the following correctly describes the outcome of applying one-hot encoding to this feature?
- A
The 'Color' feature will be replaced with three new features, one for each unique category ('Red', 'Blue', 'Green'), containing binary values (0 or 1).
- B
The 'Color' feature will be replaced with a numeric column where categories are assigned unique integers (e.g., 'Red' becomes 1, 'Blue' becomes 2, 'Green' becomes 3).
- C
The 'Color' feature will remain a single column, but its string values will be encoded as numerical values representing the frequency of each category in the dataset.
- D
The 'Color' feature will remain unchanged, as one-hot encoding does not modify the original data.
Show answer and explanation
Correct answer: A
Explanation
One-hot encoding is a common preprocessing step for categorical features in machine learning. It transforms a categorical feature into multiple binary features, one for each unique category. This enables machine learning algorithms to interpret categorical data without falsely implying an ordinal relationship between categories.
- A. Correct.
Correct: One-hot encoding replaces a categorical feature with multiple binary columns, one for each unique category. The value is 1 if the row corresponds to that category and 0 otherwise.
- B. Incorrect.
Incorrect: This describes label encoding, not one-hot encoding. Label encoding assigns integer values to each unique category, but it does not create separate columns for each category.
- C. Incorrect.
Incorrect: This describes frequency encoding, which replaces category values with their occurrence counts or proportions in the dataset, and is not related to one-hot encoding.
- D. Incorrect.
Incorrect: One-hot encoding modifies the original data by creating new binary columns for each unique category, so the original feature does not remain unchanged.