pyne
Blog

Optimising Facebook Prophet for Accurate Sales Forecasting

Csenge Orban
#Forecasting#Prophet#Machine Learning#SKU Sales
Feature image

Lessons Learned Fine-Tuning Prophet

Forecasting can feel like an endless puzzle, with no one wanting to be responsible for wrong predictions that lead to over-ordering. That’s where a machine learning forecasting model can take some weight off your shoulders. Facebook built Prophet specifically for time series forecasting. While its default model gets you started quickly, it’s worth fine-tuning for production to fit your data better. Prophet gives you a variety of parameters to adjust, and finding the right balance between overfitting and underfitting can be an art in itself. I was tasked with forecasting SKU sales quantities using a dataset with highly volatile data points (see screenshot below).

Image description

Now, let’s dive into the pitfalls I encountered and the key takeaways from fine-tuning the Prophet model.

Minimise the Parameter Grid from the Start Through EDA (Exploratory Data Analysis)

When fine-tuning any machine learning model, you define a parameter grid with the parameters you want to adjust and the range of values to try. I initially went with a large parameter grid to find the optimal combination, but it ended up taking ages. Instead, it’s more efficient to set some parameters in advance to reduce the grid size, making training and predictions faster. To help decide which parameters to fix ahead of time, I recommend spending some extra time on exploratory data analysis (EDA)—it’s invaluable for setting growth and seasonality parameters effectively.

For example, just by looking at the plotted time series, you can often see if growth is linear or logistic and if seasonality should be additive or multiplicative. This understanding reduces the parameter grid significantly and helps you zero in on the best parameters faster:

Image description Image description

In the future, I’ll definitely spend more time on EDA before diving into fine-tuning and model-building—it ultimately makes the process more focused and much faster!

Add Additional Regressors to Increase Forecast Accuracy

Starting with the default Prophet model is a good first step. Once you see the forecast, you can identify where it falls short and explore what external factors might have influenced those periods. Maybe there was a flash sale, or maybe an article about your product spiked interest. These events can be added as additional regressors to capture those previously missed peaks or dips.

Once you’ve brainstormed some possible influences, add them as regressors in your dataset, then check their correlation with your target variable (y). A strong correlation usually indicates it could be a valuable addition to the model. Plotting the regressor against y can also help confirm a consistent effect.

Note: If you add a regressor, you also need future values for it in the forecast period. Prophet requires both past and future values for additional regressors.

Example: I initially added an in_sale regressor, which flagged when items were on sale, but I noticed that Prophet struggled when there was no actual spike during the sale period in the test data. The forecast expected a surge, even though there wasn’t one, which led to errors.

Solution: Feature Engineering
I realized that consecutive days of in_sale = True have a stronger impact than just single sale days. So, I created a new feature to capture this cumulative effect, representing the duration of sales over time. This simple adjustment improved the model’s accuracy significantly.

Image description Image description

Focus on Impactful Hyperparameters; Not Everything Needs Tuning

In the beginning, I tried setting custom values for every hyperparameter, hoping it would improve my model’s performance. However, I quickly noticed that tweaking every parameter didn’t necessarily make the model better—in fact, it often performed worse than the default settings. Over-adjusting led to overfitting, where the model captured noise rather than meaningful patterns.

Over time, I learned to focus on just a few impactful hyperparameters:

In the end, I realized that the default model is often a solid starting point. When tuning, it’s more effective to focus on a few key parameters rather than trying to perfect every setting. This not only simplifies the process but also avoids the risk of overfitting.

Final Thoughts on Fine-Tuning Prophet

The Facebook Prophet model performs well with textbook data, where seasonality and changepoints happen at regular intervals and increase predictably. But with more volatile data, I found it challenging to fine-tune the model without overfitting. Key takeaways for me were to define the growth and seasonality modes in the parameter grid before running a grid or random search. Also, avoid setting all hyperparameters up front. Instead, review the default model’s forecast to identify where it goes off track, then consider any additional factors that might explain spikes, and include those as regressors. Before adding them, though, check for a strong correlation and a consistent impact of the regressor on the target variable, y.

Hopefully, these insights help make your experience with Prophet a good one!


Ready to Forecast Your Data?

Using machine learning and AI for forecasting can make planning simpler and decisions smarter, even with complex data. These tools help you match inventory to demand and keep up with market changes.

If you’re facing similar forecasting challenges, reach out to see how we can help turn your data into clear, useful insights. Visit pyne.dk/contact to get started.

← Back to Blog