QuestionQ58

VerifiedScaling and Tuning

A retail company wants to more accurately distribute products by improving forecasts of each SKU’s sales in every store. A Data Scientist proposes scaling the existing forecasting model so it produces an individual forecast for every SKU and Store ID combination. They have a cluster with 12 executors available to run this workload. The current model is written with Pandas and the Prophet forecasting library, using a Python function that takes a Pandas Data Frame containing historical sales data as a parameter to train the forecasting model.

For the next iteration, they want to make this approach more efficient with the least effort while using all available resources.

Which approach accomplishes this?

Explanation

A grouped-map Pandas UDF lets Spark provide the records for each Store-and-SKU group as a pandas DataFrame to the existing Python forecasting logic, and Spark can execute those group operations in parallel across executor tasks. This preserves the Pandas and Prophet implementation without collecting the full dataset to the driver or replacing the model. Spark documents GroupedData.apply as accepting a grouped-map pandas_udf, and documents applyInPandas as mapping each group with a pandas UDF.

Learn more

Community Discussion

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