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
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 Update Sep 19, 2017 Update Jun 27, 2017 Update Jul 8, 2017


  • 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 code, which is not automated for lag selection. The 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



  • Summary Stats on SKU 2



  • Summary Stats on SKU 3



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


  • SKU 2 - rmse = Rs. 1.9


  • SKU 3 - rmse = Rs. 1.5


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


  • SKU 2 - rmse = 50 Customers


  • SKU 3 - rmse = 52 Customers


  • 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




  1. SKU 2 - rmse = 250 Kg




  1. SKU 3 - rmse = 353 Kg




You can’t perform that action at this time.