/adv_mla_at2

This is a git repo for Advance MLA AT2 - Predicting and forecasting the volume of sales in 10 stores accross 3 diff states in the US

Primary LanguageJupyter NotebookMIT LicenseMIT

adv_mla_at2

This is a github repository for the Advance MLA Assessment 2.

We were adviced to develop two models namely:

  1. Predictive Sales Revenue Model: This model uses machine learning to predict the revenue made from sales for a specific item with its sell price, in a specific store on the given date. It makes it possible to manage inventory, plan sales, and make the most money possible.
  2. Forecasting Sales Revenue Model: This model uses time series analysis to forecast how much revenue will be made from sales of all items and stores in the next seven days. It gives us useful information for making quick decisions and allocating resources.

These models were developed and deployed on Heroku app: here


Run this code:

Set up environment using poetry

  1. Clone this repository and go to the directory by: cd adv_mla_at2
  2. Initialise the poetry project file: poetry init (Already there)
  3. Activate environment: poetry shell
  4. Install dependencies using: poetry install

Play around with notebooks

  1. Predictive modelling
  2. Forecasting

Learn about the src files

  1. filter_items.py - Used to filter out data; keep items having more than 10% of the overall sales.
  2. merge.py - Used to integrate item sell price, date from calendar and calculate revenue using the units sold.
  3. buil_features.py - Script to extract date features such as weekday, month and year.
  4. train_model.py - Helper function used to build the SGD pipeline and fit the prediction model.
  5. predict_model.py - Helper script that takes new data and extracts features of date and gives prediction on the new data.

Deploy the model in a docker container

  1. cd api
  2. docker build -t fastapi:latest .
  3. docker run -dit --rm --name adv_mla_at2_fastapi -p 8080:80 fastapi:latest

Release the model to Heroku using container Registry

  1. Login with CLI: heroku login
  2. Login to container registry: docker ps
  3. heroku container:login
  4. Push Docker-based app: heroku container:push web
  5. Deploy the changes: heroku container:release web

Access the API endpoints:

Try this out to predict revenue for an item with its sell price, at a given store and for a date: predictive api
Change the item_id, sell price and other inputs to your requirement.

/sales/national/ will give you the total revenue for the next seven days across all stores for all items.
It gives output in a list - day_one_revenue, day_two_revenue and so on.

Additional notes:

You can change the expected forecast revenue for any number of days you want. Just change the value of n_periods in the arima_pipe.predict(n_periods=7). It is in the forecast function of the main.py file.