Logistics Demand Forecast of Fresh Food E-Commerce Based on Bi-LSTM Model

Abstract

Fresh products have the characteristics of perishable, small batch and high frequency. Therefore, for fresh food e-commerce enterprises, market demand forecasting is particularly important. This paper takes the sales data of a fresh food e-commerce enterprise as the logistics demand, analyzes the influence of time and meteorological factors on the demand, extracts the characteristic factors with greater influence, and proposes a logistics demand forecast scheme of fresh food e-commerce based on the Bi-LSTM model. The scheme is compared with other schemes based on the BP neural network and LSTM neural network models. The experimental results show that the Bi-LSTM model has good prediction performance on the problem of logistics demand prediction. This facilitates further research on some supply chain issues, such as business decision-making, inventory control, and logistics capacity planning.

Share and Cite:

Ni, S. , Peng, Y. and Liu, Z. (2022) Logistics Demand Forecast of Fresh Food E-Commerce Based on Bi-LSTM Model. Journal of Computer and Communications, 10, 51-65. doi: 10.4236/jcc.2022.109004.

1. Introduction

Fresh food e-commerce is a new type of e-commerce that sells fresh products on the Internet. Fresh food e-commerce products have the characteristics of perishable, small-batch, and high frequency. These characteristics make it difficult to predict market demand, which leads to increased difficulty in controlling logistics, out-of-stock supply, and inventory management for fresh food e-commerce companies. This is very detrimental to supply chain logistics management. On the one hand, solving the problem of demand forecasting can help enterprises to make logistics and transportation planning decisions, avoid insufficient or idle transport capability, and on the other hand, it can minimize the loss caused by the hoarding of goods in logistics warehousing.

Traditional demand forecasting models include linear regression models, machine learning models, and so on. Jishan Zhu [1] established a multiple linear regression model with POS data as a predictor to forecast the demand of supply chain terminal business. This kind of simple demand forecasting model is mainly built based on historical sales data, which is suitable for the short-term demand situation of the object of prediction in a stable state and does not take too much consideration into the changes in community distribution and weather factors. Xiuzhu Zhang constructed a Bayesian network model for uncertainty demand forecasting [2]. Slimani I et al. focused on the realization and configuration of neural networks in daily demand forecasting work based on historical sales information [3]. Hongwei Ding et al. used the Adam optimization algorithm to replace the stochastic gradient descent algorithm to better reduce the prediction error of the BP neural network model [4]. Hao Xu et al. forecast supermarket sales based on univariate time series and the LSTM model [5]. Yuanming Wang introduced multivariate influencing factors into the LSTM model for sales forecasting in the e-commerce industry, which has great reference significance for the forecast of fresh food e-commerce logistics demand [6]. Ying Zhao et al. constructed an LSTM-Prophet composite prediction model. The experiments show that the LSTM model has good portability and application scenarios [7]. Lama A et al. propose an LSTM freight forecasting framework based on a k-means clustering method, which supports short- or long-term freight demand forecasting and allows forecasting to closely follow recent market trends and fluctuations [8]. The LSTM model can solve the problem of long-term dependence and use forward information to predict future demand, but ignore the impact of backward information on current data, and the prediction accuracy and model universality still need to be improved [9].

In the field of supply chain demand forecasting, most of the research usually proposes suggestions from the perspective of macro-control, without considering the real-time impact of complex factors on demand changes. As can be seen from the above, some studies have tried to use regression models, machine learning and other technical means to solve the problem of demand forecasting in traditional industries. However, as an emerging industry, the fresh food e-commerce industry, which requires extremely high timeliness and has variable influencing factors, has little research in the field of logistics demand forecasting. To achieve an effective forecast of fresh food e-commerce logistics demand, enterprises must not only take into account the overall trend and fluctuation of demand changes but also take into account the different degrees of influence of various factors on demand. Therefore, this paper proposes a fresh food e-commerce logistics demand forecasting scheme based on the Bi-LSTM model, which takes the historical sales data of fresh food e-commerce as the logistics demand, and analyzes the influence of various factors on the logistics demand. Factors that have a greater impact are retained. Then, the demand data set and the feature data set are used to construct the data set as the input of the Bi-LSTM forecasting model. Finally, the prediction results of the Bi-LSTM model are compared with the prediction results of different models.

2. Theoretical Basis of Related Research

2.1. Logistics Demand Forecasting Process

The logistics demand forecasting process includes: data acquisition and storage, data preprocessing (outliers and vacancies processing, data standardization, analysis and screening of influencing factors), model training, model prediction, and model evaluation (as Figure 1). Specifically, it is necessary to build a feasible prediction model by analyzing the correlation between the influencing factors and the logistics demand, use the existing data for model training and parameter optimization, and use the trained model to predict the changing trend of logistics demand in the future. For fresh food e-commerce logistics demand forecast, ensuring timeliness and accuracy is particularly critical. This requires enterprises to not only consider the trend and fluctuation of historical logistics demand when predicting future logistics demand but also take into account the impact of changes in known influencing factors on future logistics demand, to reduce the error of logistics demand forecast, which is caused by the change of actual influencing factors [10].

2.2. Bi-LSTM Neural Networks

2.2.1. LSTM Unit Structure

The LSTM network improves the problem that the RNN network cannot solve long-term dependencies and avoids the phenomenon of the gradient explosion of the RNN network [11]. The LSTM unit structure is shown in Figure 2.

Figure 1. Flow chart of logistics demand forecasting (Image source: The author arranges according to the actual situation).

Figure 2. The LSTM unit structure (Image source: The author organizes according to references [5] [6] [9]).

The LSTM memory unit mainly includes four structures: cell state (Ct), forget gate, input gate, and output gate. The cell state is used to hold the memory information at time t, which runs directly on the entire chain so that the information can remain unchanged when transmitted. When the information passes through the gate structure, it will selectively remove or add information to the cell state [12]. The following is the overall framework of the LSTM network:

forget gate:

f t = σ ( w f [ s t 1 , x t ] + b f ) (1)

input gate:

i t = σ ( w i [ s t 1 , x t ] + b i ) (2)

C ˜ t = tanh ( w c [ s t 1 , x t ] + b c ) (3)

output gate:

o t = σ ( w o [ s t 1 , x t ] + b o ) (4)

s t = o t tanh ( C t ) (5)

In Equation (1) to Equation (5), tanh is the hyperbolic tangent activation function; W f and W i are the weight matrices corresponding to the forget gate and the input gate respectively; W c and W o are the weight matrices corresponding to the generated candidate joining information; b f , b i , b c , b o are the bias terms of each layer.

2.2.2. The Principle of the Bi-LSTM Network

The one-way LSTM network can only make information predictions from the front to the back. Based on the one-way LSTM network, Schuster proposes a Bi-LSTM network that considers both early information and late information [13]. The structure diagram of the Bi-LSTM network is shown in Figure 3.

The Bi-LSTM network performs forward computation and backward computation synchronously. In Figure 3, the horizontal direction represents the bidirectional flow of information along the time series, and the vertical direction represents the unidirectional flow of information from the input layer to the hidden layer, and then to the output layer [14]. Among them, the hidden layer

Figure 3. Bi-LSTM network structure diagram (Image source: The author organizes according to references [14] [15]).

comprises two LSTM models, namely the forward transfer layer and the backward transfer layer [15]. After the data is input, the model will generate new latent vectors h t and h t from the former latent vector h t 1 and the latter latent vector h t + 1 respectively, and then calculate the output result S t by h t and h t . The calculation formula is as follows:

h t = LSTM ( x t , h t 1 ) (6)

h t = LSTM ( x t , h t + 1 ) (7)

S t = tanh ( W h s h t + W h s h t + b y ) (8)

In Equation (8), W h s and W h s are weight matrices; b y is the bias term.

The Bi-LSTM network performs forward calculation and backward calculation synchronously, which can memorize the overall trend and fluctuation of demand. Input the factors that affect the logistics demand into the model, so that the model can memorize the influence degree of the changes of each factor on the demand.

3. Experimental Data Set and Data Analysis

In the experiment, the data visualization method was used to analyze the spatial and temporal demand distribution characteristics of the historical data, and the correlation degree of each meteorological influencing factor was analyzed through the heat map. Then, the meteorological influencing factors whose associated value is lower than the threshold are removed, and the remaining influencing factors are used to construct the model feature set, which together with the historical sales data constitute the model input. Mining the implicit correlation information between data can provide decision support for enterprises in logistics capacity and logistics warehousing planning.

3.1. Data Collection

The meteorological data set used in the experiment comes from the Shenzhen Municipal Government Data Open Platform and the Shenzhen Meteorological Bureau, and the sales data set comes from the historical sales data of pork products of a fresh food e-commerce company in a certain outlet in Shenzhen. The time series of the dataset ranges from January 1, 2020, to March 31, 2022, with a total of 821 pieces of data. There are a few missing values in the data set, and the average value of the data before and after the missing value is taken to replace the missing value so that the subsequent experimental work can be carried out smoothly. The data items of the dataset are shown in Table 1 and Table 2.

3.2. Analysis and Screening of Influencing Factors

3.2.1. Time Factors

Figure 4 is a time series analysis of the company’s fresh food product sales data from January 2020 to March 2022. It can be seen that changes in market demand for fresh products are more time-sensitive and have obvious regularities of change. In general, in a year, the sales curve of fresh products generally increased first and then decreased. Occasionally, there is a surge in the sales curve. Judging from the time, it is obviously related to the typhoon season in Shenzhen. Every year from March, the sales volume of fresh products has soared, forming a clear

Table 1. Discrete data description of experimental dataset.

Table 2. Continuous data description of experimental dataset.

Figure 4. The change curve of sales volume of fresh products.

fault with the sales volume in February. However, in January of the following year, sales will generally decline, which is obviously related to the traditional Chinese festival Spring Festival. January and February are the months of the traditional Chinese festival Spring Festival. Due to a large number of non-native workers in Shenzhen, the period is usually accompanied by a wave of returning home, so the urban population has dropped rapidly, resulting in a decline in the demand for fresh products.

Figure 5 further studies the impact of specific time-influencing factors on the sales of fresh products. AVE in Figure 5 represents the average, and MED represents the median. It can be seen from the figure that the sales volume of fresh products from Monday to Thursday is stable. When approaching the weekend, the sales volume will rise sharply, and the sales volume on holidays is also significantly higher than that on non-holidays. In terms of months and seasons, June to August is the peak period of the year, and December to February is the low peak period. To sum up, there are four kinds of time factors (WEEKDAY, MONTH, HOLIDAY, SEASON) that are important factors affecting the sales of fresh products.

3.2.2. Meteorological Factors

The demand for fresh products is significantly affected by meteorological factors. As shown in Figure 6, the sales volume of fresh products varies with the type of weather. The sales volume on rainy days is significantly higher than that on sunny days, and typhoon weather has the most significant impact on sales volume.

Figure 7 shows the heat map of the correlation between the sales volume of pork products and 11 meteorological factors at an outlet in Shenzhen from January 2020 to March 2022.

Figure 5. The influence of time factors on the sales of fresh products.

Figure 6. The effect of weather type on fresh product sales.

It can be seen from Figure 7 that there is a strong correlation between the sales volume of fresh products and four meteorological factors, namely the highest

Figure 7. Heat map of correlation between meteorological factors and fresh product sales.

daily temperature, the lowest daily temperature, the highest ground temperature, and the lowest ground temperature. The meteorological factors with the highest correlation with the sales volume were the daily minimum temperature and the minimum ground temperature, whose values were 0.80 and 0.74, respectively. This indicates that the fluctuation of the minimum temperature will have a great impact on people’s desire to buy fresh products.

The daily maximum temperature and daily minimum temperature have a strong positive correlation with sales. Although the highest and lowest temperatures on the ground also have a strong positive correlation with sales, in fact, these two influencing factors also have a strong positive correlation with the daily maximum and minimum temperatures. Therefore, the impact of these two pairs of influencing factors on sales is the same, so the latter two influencing factors should be deleted. The remaining meteorological factors with low correlation should also be deleted, so only the weather type, daily maximum temperature, and minimum temperature are retained as meteorological factors.

4. Experiment of Fresh Food E-Commerce Logistics Demand Forecasting

4.1. Preliminary Work

The preliminary work is mainly to build the experimental environment, preprocess the data set and establish the evaluation indicators of the model prediction results.

1) Experimental Configuration

The experiment was carried out in the Windows10 system, using Anaconda Navigator (Jupyter notebook) and Python3.9 as the experimental platform, and using the neural network model such as LSTM provided by the Tensorflow framework for experimental simulation.

2) Data Set Construction

According to the above analysis, the dataset selects seven influencing factors as the feature dataset, including WEEKDAY, MONTH, HOLIDAY, SEASON, WEATHER, MAXT, and MINT. Meanwhile, SALE is used as the label dataset. The training set ratio is 0.8 and the test set ratio is 0.2.

3) Data Standardization

In order to compare and weight indicators of different units or magnitudes, it is necessary to standardize the continuous values in the data set and convert them into dimensionless pure values. The standard deviation standardization method was used in the experiment, and the formula is as follows:

X m n = x m n μ σ (9)

In Equation (9), x m n is the original data, X m n is the normalized data, μ is the mean value of the feature data, and σ is the standard deviation of the feature data.

4) Establishment of Evaluation Index

In the experiment, Coefficient of Determination ( R 2 ) and Mean Square Error (MSE) were selected as evaluation indicators to evaluate the prediction performance of the model [16].

The coefficient of determination can be used to determine the goodness of fit between the predicted value and the actual value. The closer R 2 approaches 1, the higher the goodness of fit. The formula is as follows:

R 2 = 1 i = 1 n ( y i y ^ i ) 2 i = 1 n ( y i y ¯ i ) 2 (10)

In Equation (10), y i is the true observation, y ¯ i is the mean of the true observation, and y ^ i is the predicted value. When R 2 = 1 , it means that the model predicted value is equal to the actual value, there is no error, and the model prediction accuracy is high; when R 2 = 0 , it means that the model prediction value is equal to the mean value and the model prediction accuracy is low; when R 2 < 0 , indicating that the model cannot make predictions accurately.

The mean square error refers to the mean of the sum of squares of the corresponding point errors of the predicted data and the original data. The closer MSE approaches 0, the smaller the model prediction error. The formula is as follows:

MSE = 1 n i = 1 n ( y i y ^ i ) 2 (11)

4.2. Bi-LSTM Model Construction

1) Feature Dataset and Batch Data Construction

The experiment sets the time step of the Bi-LSTM model to 7 and then utilizes the normalized original dataset to construct training and testing datasets (scales are 0.8 and 0.2, respectively). Set the buffer size to 1000 and the batch size to 128, and then use the training and testing datasets to construct training and testing batch datasets. Using a fixed-size buffer can shuffle the data randomly while setting a buffer larger than the number of data items ensures that the data is completely shuffled.

2) Model Building and Compilation

In the experiment, the number of layers of the Bi-LSTM model is set to 4 layers, and the number of units in each layer is set to 256, 256, 128, and 32 respectively. In order to prevent the model from overfitting during training, the experiment sets the dropout rate of the first two layers of network nodes to 0.3. The optimizer selects adaptive moment estimation (Adam) and the loss function selects mean square error (MSE).

4.3. Training and Comparative Analysis of Logistics Demand Forecasting Model

The experiment takes the training batch dataset as the model input, sets the number of training epochs to 60, and outputs the loss value of each epoch of training. At the same time, the BP neural network model and the LSTM neural network model were used as the control experimental group, and the same parameters as the Bi-LSTM model were set, including buffer size, batch size, and epochs. The LSTM model is set with the same number of layers, units, and dropout rate as the Bi-LSTM model, and then the three models are trained on the same dataset.

Figure 8 shows the decline of the loss function for the three models during

Figure 8. Training loss functions for three neural network models.

training. As the number of iterations increases, the loss values of the three models on the training set continue to decrease and approach 0. The loss value of the Bi-LSTM model remains low from the beginning, decreases relatively fast, and finally stabilizes at a low level. It shows that the Bi-LSTM model performs better on the training set than the other two comparison models.

4.4. Logistics Demand Prediction and Model Evaluation

1) Logistics Demand Prediction

The experiment uses three trained models to predict the logistics demand of the test batch data set. Through inverse normalization, the predicted results of the model and the actual sales data are restored to the original value. The comparison between the predicted value and the real value of the Bi-LSTM model after inverse normalization is shown in Figure 9. It can be seen from the figure that Bi LSTM model has a relatively accurate prediction effect on the data set, which can not only better predict the changing trend of data, but also have a small prediction error.

2) Model Comparison and Evaluation Analysis

In order to observe the prediction error of the three models more intuitively, the experiment subtracts the prediction value of the three models from the actual value to obtain the prediction error value of the model. The box diagram of prediction error is shown in Figure 10. Obviously, compared with the BP model and LSTM model, the prediction error value distribution of the Bi-LSTM model is more concentrated and closer to 0, indicating that the prediction accuracy of the Bi-LSTM model is higher.

After the three models complete the demand forecast, the obtained MSE and R2 are shown in Table 3. According to the evaluation index results of each model in Table 3, among the three models, the Bi-LSTM model has the lowest MSE

Figure 9. Comparison diagram of predicted value and real value of Bi-LSTM model.

Figure 10. Box diagram of model prediction error value.

Table 3. Comparison of evaluation indicators of different models.

value of the prediction result, which is 0.063, and the highest R2 value, which is 0.858, and the model fitting result is the best. The experimental results show that the Bi-LSTM model has the best prediction effect on the experimental data set compared with the other two models.

5. Conclusions

Demand forecasting has a significant impact on fresh food e-commerce logistics management. Therefore, this paper proposes a fresh food e-commerce logistics demand forecasting scheme based on the Bi-LSTM model. After experiments, the following conclusions are drawn.

The main factors affecting the demand for fresh products include whether it is weekends, holidays, months, seasons, and temperatures. Fluctuations in minimum temperatures affect customer demand for fresh produce. At the same time, due to the influence of the Spring Festival, the period from December to February has become the low peak period of demand for fresh products in a year.

According to the model prediction results, the MSE value of the Bi-LSTM model is 0.063, indicating that the model prediction error is smaller and the R2 value is 0.858, indicating that the prediction results are more accurate. This shows that the fitting effect of the Bi-LSTM model is relatively good.

Experiments show that the logistics demand forecasting scheme based on the Bi-LSTM model can take into account the overall change trend of demand and the different influences of various factors on demand. Therefore, it can meet the timeliness requirements of fresh food e-commerce companies, and is suitable for the forecasting of logistics needs of fresh food e-commerce companies. On this basis, the experiment can also do further research and development. For example, the increase in logistics cost caused by the demand forecast error can be used as the evaluation index of the model. In addition, demand forecast results can be used in business decision-making, inventory control, and logistics capacity planning.

Acknowledgements

The research was supported by Science and Technology Plan of Zigong Science and Technology Bureau (Grant No. 2018GYCX33) and the Innovation Fund of Postgraduate, Sichuan University of Science & Engineering (Grant No. y2021096).

Conflicts of Interest

The authors declare no conflicts of interest regarding the publication of this paper.

References

[1] Zhu, J.S. (2013) POS Data and Your Demand Forecast. Procedia Computer Science, 17, 8-13.
https://doi.org/10.1016/j.procs.2013.05.002
[2] Zhang, X.Z. (2017) Research on Demand Forecast in Uncertainty of Supply Chain—Based on Bayesian Network Model. Sci-Tech Innovation and Productivity, No. 2, 50-52+55.
[3] Slimani, I., Farissi, I.E. and Al-Qualsadi, S.A. (2016) Configuration of Daily Demand Predicting System Based on Neural Networks. 2016 3rd International Conference on Logistics Operations Management, Fez, 23-25 May 2016, 1-5.
https://doi.org/10.1109/GOL.2016.7731709
[4] Ding, W.H., Wang, W.G., Wan, L. and Luo, J. (2019) Prediction of Power Grid Material Demand Based on BP Neural Network. Computer Technology and Development, 29, 38-142.
[5] Xu, H. and Wang, C.Y. (2021) Demand Prediction of Chain Supermarkets Based on LSTM Neural Network. China Logistics & Purchasing, No. 3, 42-43.
[6] Wang, Y.M. (2018) Research on E-Commerce Demand Prediction Based on LSTM Neural Network. Shandong University, Jinan.
[7] Zhao, Y., Zhai, Y.W., Chen, J.J. and Teng, J. (2020) Time Series Forecasting Model Based on a Nonlinear Combination of LSTM-Prophet. Computer and Modernization, No. 9, 6-11+18.
[8] Lama, A., Mahmassani, H.S. and Chen, Y. (2020) Reinforcement Learning Framework for Freight Demand Forecasting to Support Operational Planning Decisions. Transportation Research Part E: Logistics and Transportation Review, 137, Article ID: 101926.
https://doi.org/10.1016/j.tre.2020.101926
[9] Nahid-Al-Masood Rafi, S.H., Deeba, S.R. and Hossain, E. (2021) A Short-Term Load Forecasting Method Using Integrated CNN and LSTM Network. IEEE Access, 9, 32436-32448.
https://doi.org/10.1109/ACCESS.2021.3060654
[10] Petroşanu, D.-M. and Pîrjan, A. (2021) Electricity Consumption Forecasting Based on a Bidirectional Long-Short-Term Memory Artificial Neural Network. Sustainability, 13, Article No. 104.
https://doi.org/10.3390/su13010104
[11] Ma, C., Dai, G. and Zhou, J. (2021) Short-Term Traffic Flow Prediction for Urban Road Sections Based on Time Series Analysis and LSTM_BILSTM Method. IEEE Transactions on Intelligent Transportation Systems, 23, 5615-5624.
https://doi.org/10.1109/TITS.2021.3055258
[12] Nguyen, H.D., Tran, K.P., Thomassey, S. and Hamad, M. (2021) Forecasting and Anomaly Detection Approaches Using LSTM and LSTM Autoencoder Techniques with the Applications in Supply Chain Management. International Journal of Information Management, 57, Article ID: 102282.
https://doi.org/10.1016/j.ijinfomgt.2020.102282
[13] Schuster, M. and Paliwal, K.K. (1997) Bidirectional Recurrent Neural Networks. IEEE Transactions on Signal Processing, 45, 2673-2681.
https://doi.org/10.1109/78.650093
[14] Le, T., Vo, M.T., Vo, B., Hwang, E.J. and Baik, S.W. (2019) Improving Electric Energy Consumption Prediction Using CNN and Bi-LSTM. Applied Sciences, 20, Article No. 4237.
https://doi.org/10.3390/app9204237
[15] Zheng, Z., Feng, L., Liu, R., Wang, X. and Sun, Y. (2022) Ultra-Short-Term Forecast of Multi-Energy Load for Integrated Energy System Based on Attention Mechanism and Bilstm. Journal of Physics: Conference Series, 2271, Article ID: 012018.
https://doi.org/10.1088/1742-6596/2271/1/012018
[16] Zhou, Z.H. (2016) Machine Learning. 1st Edition, Tsinghua University Press, Beijing.

Copyright © 2024 by authors and Scientific Research Publishing Inc.

Creative Commons License

This work and the related PDF file are licensed under a Creative Commons Attribution 4.0 International License.