- 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.
- 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 Variables and Definition
- Input variables
- AvgSP - Average Selling Price of SKU
- OP - Average Selling Price of Onion
- 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
- 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 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 is predicted using time series forecasting.
- 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.
- LSTM is a special type of Neural Network which remembers information across long sequences to facilitate the forecasting.
- Forecasting results
- SKU 1 - rmse = Rs. 1.266
- SKU 2 - rmse = Rs. 1.9
- SKU 3 - rmse = Rs. 1.5
- @CustomerCount is predicted using the same method as @AvgSP
- 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.
- 3-layer Neural Network using Keras Library (tensorflow backend)
- The network is made up of 3 layers:
- 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)
- 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)
- Output Layer
- Converts the processed results into a reverse scaled output.
- SKU 1 - rmse = 180 Kg
- SKU 2 - rmse = 250 Kg
- SKU 3 - rmse = 353 Kg