As businesses grow, forecasting becomes an increasingly important task. Imagine an electronic store having a shortage of goods during Black Friday, that would be a huge amount of income lost. Accurate forecasting can help companies optimise inventory, manage supply chain logistics, and increase profitability. Amazon Forecast is a machine learning service that can help businesses predict future demand with high accuracy. In this blog post, we'll cover the basics of using Amazon Forecast for demand prediction, look at what-if analysis and possible MLOps solution.
As with every other service in AWS, there is always an option of setting it up from AWS Console, but if there is a need for automation, it is also possible to use Infrastructure as Code solutions, like CloudFormation or CDK. The automation will take additional time to set up, but will make a solution more reusable and less error-prone. I, personally, prefer familiarising myself with any AWS service through AWS Console first - it gives better overview and understanding of basic features.
Our first step is to gather historical data on past demand for your product/service and structure it into datasets. Data collection and cleaning is a huge topic in itself that we will not cover fully in this blogpost, but the general rules are:
Our example case is big retail store that sells all kinds of products: electronics, groceries, sport goods, etc. There is a data for the last 30 days of sales available, that we've cleaned before further processing.
Now it is time to work with Amazon Forecast. First we have to create an S3 bucket, that will store all our data. After the bucket is created, we have to import our datasets (they can be stored either in CSV
or PARQUET
format). There are 3 types of datasets that you can import into Amazon Forecast:
Importing each of these datasets into Amazon Forecast takes around 30 minutes, however it is possible to run these jobs in parallel and speed up the process.
This is where the real magic happens! Amazon Forecast uses advanced algorithms to train a model based on configurations that we specify in this section. The most notable options are:
This is the most time-consuming part of interactions with Amazon Forecast. The job could take 2-3 hours, depending on amount of data.
Now that we have datasets ready and predictor model trained, we can create a Forecast. For that we just have to pick a name and choose a predictor, that we created before. After that there are 2 options: we can either query newly-created forecast using dashboards in service itself or export the forecast to Amazon QuickSight. In my opinion, the last option feels more refined and feature-rich.
The setup is quite simple. We just have to export our forecast to S3 bucket and then reference it during analysis creation in Amazon QuickSight. After the initial steps are done, we can get a forecast dashboard for a specified period of time, either for all items or for a specific item. The dashboard below shows a demand prediction for a single item (coffee) for 30 days period:
The forecast will give you transparent and accurate prediction of future demand for a specific item.
We can go even further and implement what-if analysis. Using this insight we can go through additional scenarios and see how the demand will change, if the target value is different from the predicted.
As I mentioned before, automation takes time but will pay off eventually. Below is a sample architecture that will do most of the job for you: from data preparation to forecasting and evaluation. Setup is implemented using CloudFormation.
If you would like to dive deeper in Amazon Forecast for retail, please follow this link.
If you are interested in various forecast-samples from Amazon, please follow this link.
Demand forecasting is crucial for businesses of all sizes. The applications of Amazon Forecast are vast and varied, ranging from demand and financial planning to resource allocation, energy management, and weather predictions. This powerful tool not only helps you generate predictions with great accuracy but also enables you to conduct what-if analysis to assess the potential impacts of various business decisions. By setting up a project, training a model, and harnessing the forecast generated by Amazon Forecast, you can streamline your business operations and secure a competitive edge.