QuestionQ11

VerifiedUsing Spark ML

A Machine Learning Engineer is working with a Spark DataFrame that contains 100 million retail-transaction rows across thousands of stores. Each store needs its own demand-forecasting model, using the same scikit-learn pipeline. The engineer wants to train and apply these models in parallel for every store without collecting the data to the driver.

Which approach accomplishes this?

Explanation

GroupedData.applyInPandas() maps a pandas UDF over each Spark group and returns the combined results as a Spark DataFrame. Grouping by store_id therefore gives the training function all rows for one store at a time on Spark executors, allowing a separate scikit-learn pipeline to be fitted and used per store without collecting the complete dataset to the driver. It requires a result schema and may require sufficient executor memory for each individual group.

Learn more

Community Discussion

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