QuestionQ123

VerifiedData Processing

A data scientist is preparing a machine-learning dataset in Databricks. The dataset includes a categorical feature named color, with the values “red”, “blue”, and “green”. They want to apply one-hot encoding to transform this feature for model training.

Which approach correctly implements one-hot encoding for the color feature with PySpark?

Explanation

In PySpark ML, StringIndexer converts string categories into numeric indices, OneHotEncoder converts those indices into sparse binary vectors, and VectorAssembler combines the encoded output into the final feature vector used for model training.

Learn more

Community Discussion

No comments yet. Be the first to start the discussion!