Databricks Machine Learning Associate Question 532
Select 2In which of the following scenarios would one-hot encoding be appropriate for preparing a dataset for a machine learning model?
- A
A dataset contains a 'City' column with categorical values like 'New York', 'San Francisco', and 'Chicago', and a linear regression model will be applied.
- B
A dataset contains a 'Temperature' column with continuous numerical values, and a decision tree model will be applied.
- C
A dataset contains a 'Product Category' column with 10 unique categorical values, and a logistic regression model will be applied.
- D
A dataset contains a 'Customer Age' column with discrete numerical values, and a clustering algorithm will be applied.
Show answer and explanation
Correct answers: A, C
Explanation
One-hot encoding is useful for converting categorical variables into a numerical format that machine learning models can interpret. It is appropriate for columns with categorical data, such as 'City' or 'Product Category', but not for continuous or discrete numerical variables.
- A. Correct.
One-hot encoding is appropriate here because the 'City' column is categorical, and linear regression cannot interpret categorical data directly. One-hot encoding converts the categorical values into a format suitable for the model.
- B. Incorrect.
One-hot encoding is not appropriate for continuous numerical data like 'Temperature', as it is already in a format suitable for machine learning models.
- C. Correct.
One-hot encoding is appropriate here because the 'Product Category' column is categorical, and logistic regression requires categorical variables to be converted into numerical representations.
- D. Incorrect.
One-hot encoding is not appropriate for discrete numerical data like 'Customer Age'. Discrete numerical data should either be left as-is or scaled, depending on the model being used.