How do you score a fitted Spark ML PipelineModel on a streaming DataFrame?
- 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: Score a Spark ML model for a batch or streaming use case.
Scoring Spark ML for batch or streaming is named.
Why A is the answer
Call model.transform(streaming_df) and write the result with writeStream
Spark ML transformers work on streaming DataFrames, so transform applies the model to each micro-batch.
Remember: transform the stream.
How it works
Spark ML scoring is the same API for batch and streams.
In detail
- transform works on streams.
- writeStream sends results out.
Every option, checked
Knowing why each wrong option fails is how you rule it out on exam day.
A. Call model.transform(streaming_df) and write the result with writeStreamRight
transform the stream.
B. Collect the stream to the driver every minute and call predict on a pandas DataFrameWrongMost tempting
Collecting to the driver breaks scale.
Why it tempts: pandas predict is familiar.
C. Retrain the model on every micro-batchWrong
Scoring does not retrain.
D. Convert the stream to CSV firstWrong
Conversion is unnecessary.
Use case
An illustrative scenario, not a real incident.
Illustrative: click events are scored as they arrive and written to a Delta table.
See it in different ways
sequenceDiagram participant P0 as Stream source participant P1 as PipelineModel participant P2 as Delta sink P0->>P1: micro-batch P1->>P2: predictions via writeStream
How to read this chart
- 1. Stream source sends "micro-batch" to PipelineModel.
- 2. PipelineModel sends "predictions via writeStream" to Delta sink.
mindmap
root(("Spark ML scoring"))
n1["Batch"]
n2["transform df"]
n3["Streaming"]
n4["transform stream"]
n5["writeStream"]How to read this chart
- The centre is "Spark ML scoring".
- "Batch" covers "transform df".
- "Streaming" covers "transform stream", "writeStream".