QuestionQ83

VerifiedUsing Spark ML

A Data Scientist is building an MLlib Pipeline to predict customer churn. The data includes a categorical feature named vehicle_type, and the Data Scientist wants to one-hot encode this feature for logistic-regression models. During inference, the Pipeline must skip rows that contain an unseen category.

Which method correctly transforms the categorical feature?

Explanation

StringIndexer converts the string category column to numeric category indices and supports handleInvalid="skip", which filters rows containing unseen or null categories. OneHotEncoder then converts those indices into a binary vector, and VectorAssembler combines that vector into the model feature column. This ordering also satisfies the requirement for logistic regression to receive vectorized numeric features.

Learn more

Community Discussion

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