Which stage order builds a valid Spark ML pipeline for string and numeric columns?
- Exam domain
- Model Development44% of the exam
- Difficulty
- Medium
- In this mock
- 22 questions on this domainPractise this domain
Why the exam asks this
Model Development (44% of the exam)
Objective in the exam guide: Construct an ML pipeline using SparkML.
Constructing a Spark ML pipeline is named.
Why A is the answer
StringIndexer, OneHotEncoder, VectorAssembler, then LogisticRegression
Strings are indexed, indices are one-hot encoded, all features are assembled into one vector, and the estimator comes last.
Remember: Index, encode, assemble, fit.
How it works
Pipeline stages run in order, so dependencies decide the order.
In detail
- Index, encode, assemble, model.
- The estimator is the last stage.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. StringIndexer, OneHotEncoder, VectorAssembler, then LogisticRegressionRight
Index, encode, assemble, fit.
B. VectorAssembler on the raw string columns, then StringIndexer on the assembled vectorWrong
VectorAssembler needs numeric inputs.
C. LogisticRegression first, then StringIndexer, then VectorAssemblerWrong
The model must come after the features exist.
D. OneHotEncoder, then StringIndexer, then LogisticRegressionWrongMost tempting
OneHotEncoder needs indices first.
Why it tempts: Both encoders are needed, but order matters.
Use case
An illustrative scenario, not a real incident.
Illustrative: a churn pipeline indexes plan and region, assembles them with tenure and fits a classifier.
See it in different ways
flowchart LR S0["StringIndexer"] --> S1["OneHotEncoder"] --> S2["VectorAssembler"] --> S3["LogisticRegression"]
How to read this chart
- Read it in order: StringIndexer, then OneHotEncoder, then VectorAssembler, then LogisticRegression.
sequenceDiagram participant P0 as Pipeline participant P1 as Stages participant P2 as PipelineModel P0->>P1: fit each in order P1->>P2: fitted stages
How to read this chart
- 1. Pipeline sends "fit each in order" to Stages.
- 2. Stages sends "fitted stages" to PipelineModel.