Databricks Machine Learning Associate Question 530
Single answerYou are working on a machine learning pipeline in Databricks, and your dataset contains a categorical feature called 'Region' with values ['North', 'South', 'East', 'West']. You want to prepare this feature for a machine learning model using one-hot encoding. Which of the following statements is correct regarding one-hot encoding in Databricks?
- A
One-hot encoding will create a new column for each unique value in 'Region', with binary values indicating the presence of the corresponding category.
- B
One-hot encoding will replace the 'Region' column with a single column containing integer values representing each category.
- C
One-hot encoding will create a single column with floating-point values between 0 and 1 representing each category.
- D
One-hot encoding is not supported in Databricks and requires external libraries like Scikit-learn.
Show answer and explanation
Correct answer: A
Explanation
One-hot encoding is a common method for representing categorical data in machine learning models. In Databricks, it can be implemented using PySpark's OneHotEncoder transformer, which creates separate binary columns for each unique category in a categorical feature. This allows models to process categorical data effectively without assuming any ordinal relationships between categories.
- A. Correct.
Correct: One-hot encoding creates new binary columns for each unique category in the categorical feature, where each row has a value of 1 in the column corresponding to its category and 0 elsewhere.
- B. Incorrect.
Incorrect: This describes label encoding, not one-hot encoding. Label encoding assigns integer values to categories but does not create multiple columns.
- C. Incorrect.
Incorrect: This is not how one-hot encoding works. It does not produce floating-point values between 0 and 1.
- D. Incorrect.
Incorrect: Databricks supports one-hot encoding using built-in libraries like PySpark's
pyspark.ml.feature.OneHotEncoder.