Skip to content
Predicting the demand of food amenities using LSTM and MLP
Python Jupyter Notebook
Branch: master
Clone or download
Latest commit 6696b2f Sep 20, 2017
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
Approach 4 notebook (App format).ipynb Add files via upload Jun 26, 2017
README.md Update README.md Sep 19, 2017
attempt4.py Update attempt4.py Jun 27, 2017
complete_code.py Update complete_code.py Jul 8, 2017

README.md

Food-amenities-demand-prediction

  • Predicting the demand of food amenities using LSTM and 3-layer neural network.
  • To run the given codes, install Keras with tensorflow backend in your IPython shell (preferably Anaconda).
  • The .py file is a looping code, while the .ipynb is a test code.
  • Note - The compiled results and graphs are based on the attempt4.py code, which is not automated for lag selection. The complete_code.py file contains automation for lag selection.

Business Problem

  • Predicting the demand quantity of food amenities
  • No input is at disposal, hence the input variables need to be forecasted and then the target variable is regressed through the forecasted input variable

Data Definition

Data Variables and Definition

  • Input variables
  1. AvgSP - Average Selling Price of SKU
  2. OP - Average Selling Price of Onion
  3. CustomerCount - Total GT Customers for the given SKU ( = CustomerCount + Missed Customers)
  • Target Variable - ActualDemand of SKU ( = Ordered Quantity + Missed Demand)

Time Period considered - 17/03/2017 to 22/06/2017

Data Understanding and Processing

Outlier Treatment

  • Values below 3rd percentile of the sample and above 97th percentile of the sample are converted to their respective buffers
  • Only @CustomerCount and @ActualDemand are considered for outlier treatment

Summary Statistics

  • Summary Stats for SKU 1

input_var_summ

ouput_var_summ

  • Summary Stats on SKU 2

sums_inp_carr

sums_out_carr

  • Summary Stats on SKU 3

ridge_inp_summ

ridge_out_sums

Training and Test Datasets

  • The last week of the complete dataset is considered for testing while the rest of the dataset is considered for training

Function to create Data Input to model

  • AvgSP
  1. @AvgSP is predicted using time series forecasting.
  2. Long Short-Term Memory (Recurrent Neural Network) method is used for forecasting. The forecasting problem is now considered as a supervised learning problem where the input is the value prior to the target day.
  3. LSTM is a special type of Neural Network which remembers information across long sequences to facilitate the forecasting.
  4. Forecasting results
  • SKU 1 - rmse = Rs. 1.266

avgsp_pred_cucum

  • SKU 2 - rmse = Rs. 1.9

avgsp_pred_carr

  • SKU 3 - rmse = Rs. 1.5

ridge_avgsp

  • CustomerCount
  1. @CustomerCount is predicted using the same method as @AvgSP
  2. Forecasting Results
  • SKU 1 - 12 Customers

cc_pred_cucum

  • SKU 2 - rmse = 50 Customers

cc_pred_carr

  • SKU 3 - rmse = 52 Customers

ridge_cc_pred

  • Onion Price is known with good accuracy due to information about the lot size.

Data Modelling

Model Name

  • 3-layer Neural Network using Keras Library (tensorflow backend)
  • The network is made up of 3 layers:
  1. Input layer
  • Takes input variables and converts them into input equation
  • Parameters: no. of neurons (memory blocks) = 16, activation function = linear, weight initializer = normal distribution, kernel and activity regularizer = L1 (alpha = 0.1)
  1. Hidden Layer
  • The processing (optimization) takes place in this layer.
  • Parameters: no. of neurons = 8, activation function = linear, weight initializer = normal distribution, kernel and activity regularizer = L1 (alpha = 0.1)
  1. Output Layer
  • Converts the processed results into a reverse scaled output.

Model Performance

  1. SKU 1 - rmse = 180 Kg

training_fit_cucum

pred_cucum

forecast_cucum

  1. SKU 2 - rmse = 250 Kg

train_dem_carr

dem_pred_carr

carr_dem_fore

  1. SKU 3 - rmse = 353 Kg

ridge_train_dem

ridge_dem_pred

ridge_dem_fore

You can’t perform that action at this time.