QuestionQ127

VerifiedModel Development

A data scientist wants to use Spark ML to one-hot encode the categorical features in their PySpark DataFrame, features_df. The names of the string columns are stored in the input_columns variable.

They developed the following code block to perform this task:

Question Image

The code block returns an error. Which adjustment does the data scientist need to make to complete this task?

Explanation

Spark ML OneHotEncoder converts category-index columns into binary vector columns; it does not take raw string categorical columns as input. StringIndexer must first map each string category to a numeric index, and those indexed columns are then supplied to the encoder. OneHotEncoder — PySpark documentation

Learn more

Community Discussion

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