Databricks Machine Learning Associate Question 533
Select 2You are working on a dataset containing categorical features such as 'Color' (with values 'Red', 'Green', 'Blue') and 'Temperature' (with values 'Low', 'Medium', 'High'). You are considering whether to apply one-hot encoding to these features. Which of the following scenarios are appropriate for using one-hot encoding?
- A
The 'Color' feature is being used as input to a linear regression model.
- B
The 'Temperature' feature is ordinal and used as input to a decision tree model.
- C
The 'Color' feature is being used as input to a neural network.
- D
The 'Temperature' feature is ordinal and encoded directly as numerical values (e.g., 0 for 'Low', 1 for 'Medium', 2 for 'High') for a linear regression model.
- E
The 'Color' feature contains 50 unique categories and is being used as input to a gradient-boosted tree model.
Show answer and explanation
Correct answers: A, C
Explanation
One-hot encoding is suitable when categorical features are non-ordinal and used with models like linear regression or neural networks that require numerical inputs while avoiding any assumptions about relationships between categories. However, it is unnecessary (and sometimes counterproductive) for ordinal data, as it loses the inherent order, or for models like decision trees and gradient-boosted trees that can handle categorical data efficiently.
- A. Correct.
One-hot encoding is appropriate for the 'Color' feature in a linear regression model because it converts the categorical values into a format that the model can process effectively, avoiding any assumption of ordinality or numerical relationships between categories.
- B. Incorrect.
One-hot encoding is generally not necessary for the 'Temperature' feature in this case because decision tree models can handle ordinal features effectively without requiring encoding. The natural order in the data can be preserved.
- C. Correct.
One-hot encoding is appropriate for the 'Color' feature in a neural network because neural networks typically require numerical inputs, and one-hot encoding ensures categorical data is represented without implying any ordinal relationship.
- D. Incorrect.
One-hot encoding would not be appropriate here because encoding ordinal data like 'Temperature' into numerical values already captures the order, which is meaningful for linear regression. Using one-hot encoding would lose the ordinal information.
- E. Incorrect.
One-hot encoding is not ideal for the 'Color' feature with 50 unique categories in a gradient-boosted tree model because tree-based models can handle categorical features effectively without explicit encoding and adding many one-hot encoded columns can lead to inefficiency.