Full text
i Forecasting sales and transactions of fast-food stores Cristina Isabel Palma Mousinho A Proof of Concept Internship report presented as partial requirement for obtaining the Master’s degree in Advanced Analytics
i Forecasting sales and transactions of fast-food stores A proof of concept Cristina Isabel Palma Mousinho MAA 2021
i
ii NOVA Information Management School Instituto Superior de Estatística e Gestão de Informação Universidade Nova de Lisboa FORECASTING SALES AND TRANSACTIONS OF FAST-FOOD STORES: A PROOF OF CONCEPT by Cristina Isabel Palma Mousinho Internship report presented as partial requirement for obtaining the Master’s degree in Data Science and Advanced Analytics Advisor: Mauro Castelli External Advisor: Pedro Freitas Lopes
iii August 2021 DEDICATION To all the teachers and professors that led me to become who I am today.
iv ACKNOWLEDGEMENTS This report would not be possible if two people did not believe in me: my external supervisor, Pedro Freitas Lopes, and my internal supervisor, Mauro Castelli. Thank you, Pedro, for taking your chance on me. For listening to my ideas as you did to any other teammate. Together with everyone else on our team, you taught me there is no weakest link. Each one of us has strengths and downfalls. That is why we are a team: to give what we have, and to receive what we need. I am finishing my internship feeling like a part of the Noesis family, especially a part of our little family. Thank you again, for taking me in, and for putting me as a person above me as an employee. And none of this would be possible without Mauro. I must thank you for your excitement and availability, never making me wait. Thank you for your hard work, for accepting me as an advisee, and for all you taught me, both inside and outside of classes. I must also express my deepest gratitude to those who, in addition to Pedro Lopes, worked by my side during the time I was an intern at Noesis: André Castro, Fábio Paixão, Carolina Carvalho, Ana Silva, Diogo Reis, Pedro Santos, and Ana Carolina Carrilho. And finally, to all those who listen to me complain, but never complain about listening to me: Mom, Dad, Guilherme, Jack, Rita, Milene, Abdallah, Ravi, Campos, Escária, Ricardo, Paulo and Paula, a big, big thank you.
v ABSTRACT As time goes on, more and more clients look for solutions to their data-related problems. During a 9- month internship at the Portuguese consulting company Noesis, a request was presented by a customer that wished to improve the forecasting capabilities of their fast-food chain, on sales and transactions, for four different distribution channels, and globally. Following a data analytics approach, hundreds of time series were examined, external variables were added, and two algorithms were used - ARIMA and Facebook’s Prophet. Both models were evaluated, and as each of them performed better in different segments, a hybrid system was implemented, successfully completing the task at hand. Based on the results, future improvements and recommendations were also identified. KEYWORDS Machine Learning; Forecasting demand; Time series; ARIMA; Facebook Prophet.
vi INDEX 1. Introduction .................................................................................................................. 1 1.1. Noesis as a company ............................................................................................. 1 1.1.1. Internship overview ........................................................................................ 2 1.2. The project ............................................................................................................. 2 2. Literature review .......................................................................................................... 3 2.1. Introduction ........................................................................................................... 3 2.2. Time series Forecasting ......................................................................................... 3 2.2.1. Measuring forecast error ............................................................................... 6 2.3. ARIMA model ......................................................................................................... 8 2.3.1. Autoregressive model (AR) ............................................................................. 8 2.3.2. Moving-average model (MA) ....................................................................... 11 2.3.3. Integration (I) ................................................................................................ 11 2.3.4. ARIMA pros and cons ................................................................................... 12 2.4. Facebook’s Prophet algorithm ............................................................................ 12 2.4.1. Additive regression ....................................................................................... 12 2.4.2. Trend ............................................................................................................ 13 2.4.3. Annual and weekly seasonality .................................................................... 14 2.4.4. Holidays ........................................................................................................ 15 2.4.5. Prophet pros and cons ................................................................................. 16 2.5. Previous works on forecasting meal-related demand ........................................ 16 2.5.1. Previous works on forecasting fast-food related demand ........................... 18 3. Methodology .............................................................................................................. 20 3.1. Project introduction ............................................................................................ 20 3.1.1. Stores ............................................................................................................ 20 3.1.2. Variables ....................................................................................................... 22 3.1.3. Development tools ....................................................................................... 22 3.1.4. Success metrics ............................................................................................. 22 3.2. Roadmap .............................................................................................................. 23 3.3. Data validation and functional considerations ................................................... 23 3.4. Data Analysis and exploration ............................................................................. 24 3.4.1. Time series visualisation ............................................................................... 25 3.4.2. Outlier detection and analysis ...................................................................... 26 3.5. Development and evaluation of forecasting algorithms .................................... 27
vii 3.5.1. ARIMA ........................................................................................................... 27 3.5.2. Prophet ......................................................................................................... 29 4. Results and discussion ................................................................................................ 31 5. Conclusions ................................................................................................................. 39 6. Limitations and recommendations for future works ................................................. 40 7. Bibliography ................................................................................................................ 42 8. Appendix ..................................................................................................................... 44 8.1. Time series of total transactions from 2018 to 2020, in store 9999 ................... 44 8.2. Time series of eat-in sales from 2018 to 2020 .................................................... 44 8.3. Time series of eat-in transactions from 2018 to 2020 ........................................ 45 8.4. Time series of take-out sales from 2018 to 2020 ................................................ 45 8.5. Time series of take-out transactions from 2018 to 2020 .................................... 46 8.6. Time series of delivery sales from 2018 to 2020 ................................................. 47 8.7. Time series of delivery transactions from 2018 to 2020 ..................................... 47 8.8. Time series of drive sales from 2018 to 2020 ..................................................... 48 8.9. Time series of drive transactions from 2018 to 2020 ......................................... 48 8.10. Time series of total sales from 2018 to 2020 .................................................... 49 8.11. Time series of total transactions from 2018 to 2020 ........................................ 50 8.12. After-PoC weekly results ................................................................................... 51 8.13. Qlik Sense dashboard ........................................................................................ 52
3 2. LITERATURE REVIEW 2.1. INTRODUCTION Nowadays, more companies are looking to forecast their demand, to adapt their management decisions to the expected future demand. Forecasting techniques can be divided into three big categories: (1) judgment, (2) causal, and (3) time series methods (Krajewski et al., 2015). In this report study case, the company had been using mainly judgment methods. The employee assigned to the task of predicting sales and transactions had gained their knowledge through experience, knowing which factors influenced customer demand. For example, it was previously known that June 1st, ‘Children’s Day’ in Portugal, was a holiday that made sales spike in almost every store. Though these estimates were fairly successful, the franchising has more than 100 different stores. This makes the task a lot harder, as every store will have its behavior, having to be analysed separately. The client requested that Noesis developed a forecasting technique using time series methods, which can be expanded to all stores without the need of looking at their data one by one. As always, the client had to become aware that sometimes the effort of improving a model might be too big in comparison to the expected improvement. It was important to make them aware of such a trade-off between effort and precision. The team of developers attempted to increase the precision with minimum effort, trying to reach good results in the least amount of time. This literature section begins with a summary of the literature study that had to be made on time series forecasting in general. It also mentions the used models: ARIMA and Facebook’s Prophet. And finally, it infers about previous works about fast-food/meal demand forecasting. 2.2. TIME SERIES FORECASTING In “Time Series Analysis: Forecasting and Control”, Box et al. (2015), describe a time series as “a sequence of observations taken sequentially in time” (p. 19). A time series can be either continuous or discrete. When observations are logged continuously over some time interval, one is looking at a continuous time series. When they are logged at fixed time intervals, observations will make up a discrete time series (Brockwell & Davis, 2002). A discrete time series can be originated in three different ways: By retrieving data from a continuous time series, only in fixed time intervals (for example, a store might keep track of the number of clients inside it at every second, but one might retrieve the number only every hour). By aggregating data over a period (which is the case at study, where all sales and transactions over a day were aggregated). By keeping track of inherently discrete data (for example, the number of employees working in a particular store every day). An example of a discrete time series is presented in Figure 2.1.
4 According to Montgomery et al. (2015), “a forecast is a prediction of some future event or events” (p. 1). When forecasting a time series, using the so-called “time series methods”, one must consider that the future values will be related to the past, assuming the historic data follows a mathematical function that can be used to predict the future. Supposing a collection of available observations that are discrete and spaced apart at equal distances, and that one pretends to forecast sales, they can think of z t as being the sales at the current day t , making z t-1 yesterday’s sales, z t-2 the number of sales from the day prior to yesterday, etc. Using those past observations, forecasts for the sales of the next day l , l = 1, 2, 3, … can be generated. Given the time series patterns on average, trends, seasonality, and cycle, the model assumes those patterns will be repeated in the future. If 𝑧𝑡(𝑙) represents the forecast made at origin t for the sales of a lead day 𝑙, z t+l , one can say the function 𝑧𝑡(𝑙) provides forecasts for all future lead times, by using all 𝑛 available observations, both current and past, z t-1 , z t-2 , z t-3 , …, z t-n . Such function can be called the forecast function at origin t (Box et al., 2015; Krajewski et al., 2015). Over the years, scientists have studied different forecasting functions. An example can be given by a simple regression model, 𝑦𝑡= 𝑥𝑡𝛽+𝜔𝑡, (2.1) with 𝑥𝑡 = {𝑥𝑡} being the collection of observed sales, and 𝜔𝑡 being an unobservable white-noise sequence of independently and identically distributed random variables (Pollock, 1999). The general temporal regression model, a more complex one, which looks to establish a relationship between any number of consecutive elements of 𝑥𝑡, 𝑦𝑡, and 𝜀𝑡, is given by: 𝑦𝑡= ∑−𝛼𝑖 𝑝 𝑖=1 𝑦𝑡−𝑖+ ∑𝛽𝑥𝑡−𝑖 𝑘 𝑖=0 + ∑𝜇𝑖𝜔𝑡−𝑖 𝑞 𝑖=0 , (2.2) where it is assumed that 𝛼0=1. The sums of the function can be infinite, but for the model to be viable, the sequences of coefficients {𝛼𝑖},{𝛽𝑖}, and {𝜇𝑖} must depend only on a limited number of parameters (Pollock, 1999). As one can compare in Figure 2.2 and Figure 2.3, two years of sales are clearly similar, and 2019 sales can probably be predicted based on the 2018 ones. Figure 2.1 – Time series of total sales (in euros) from 2018 to 2020, in store 6
5 Figure 2.3 – Decomposition of the total sales time series during 2019, in store 6 Figure 2.2 – Decomposition of the total sales time series during 2018, in store 6
6 2.2.1. Measuring forecast error In 1978, George E. P. Box states “All models are wrong, but some are useful.”. The short version of this famous statement is still used in statistics to this day, “All models are wrong”. This means that though a scientific model can be valuable, it is almost (if not) impossible to make them 100% accurate. That is exactly how forecasting performance is measured, by calculating its error. As stated in “Operations Management: Processes and Value Chains”, a book by Lee J. Krajewski, Manoj K. Malhotra, and Larry P. Ritzman, one can measure forecast error using five different techniques. 2.2.1.1. Mean Absolute Deviation Using the MAD technique, one will have an idea about the variance present in a dataset, by averaging the distance between each data point and the prediction, which translates to the following equation: 𝑀𝐴𝐷= 1 𝑇∑|𝑋𝑡− 𝑋𝑡| 𝑇 𝑡=1 , (2.3) where T is the number of observations, 𝑋𝑡 is the observed value at time t, and 𝑋𝑡 is the forecasted value for time t. The mean absolute deviation is commonly used. However, it can lead to errors in interpretation. Sometimes the MAD might be very small, but only because the demand is low. If the algorithm picks up on those null demands, the forecasts will start being lower and lower, leading to a lower MAD. As the algorithm is re-assured of these lower errors, it might start predicting in a biased way, foreseeing values lower than the real demand (Wallström & Segerstedt, 2010). 2.2.1.2. Mean Squared Error The MSE measurement is similar to the MAD one. Instead of averaging the distance between data points and the mean, one must average the squared difference between the forecasted and actual values: 𝑀𝑆𝐸= 1 𝑇∑(𝑋𝑡− 𝑋𝑡)2 𝑇 𝑡=1 , (2.4) Since the MSE is associated with the standard variation of forecast errors, Silver (et al., 1998) recommends its use. Nevertheless, one should keep in mind that this measurement is sensitive to outliers and may produce smaller errors simply due to its squared function (Wallström & Segerstedt, 2010).
7 2.2.1.3. Mean Absolute Percentage Error The MAPE is calculated by averaging the absolute percentage between the forecasted and real values: 𝑀𝐴𝑃𝐸= 100 𝑇∑|𝑋𝑡− 𝑋𝑡| 𝑋𝑡 𝑇 𝑡=1 , (2.5) Since the error is provided in terms of percentages, it becomes easier to understand, and that makes it very commonly used. Also, because the percentages are absolute, situations in which negative errors would cancel out the positives are avoided. It is because of its easy interpretability that MAPE was used to measure the prediction error of the Proof of Concept presented in this report. However, MAPE cannot be used when the real value is null. The Proof of Concept did not have that problem, as will be explained later in this report. Still, if one wishes to use the MAPE but is faced with such a problem, the use of the Symmetric Mean Absolute Percentage Error might be considered. The sMAPE can vary between -200% and 200%, and is given by the following equation: 𝑠𝑀𝐴𝑃𝐸= 100 𝑇∑|𝑋𝑡− 𝑋𝑡| (𝑋𝑡+ 𝑋𝑡)2 ⁄ 𝑇 𝑡=1 (2.6) Besides avoiding the zero-demand problem, another reason to use sMAPE is the fact that the error becomes symmetric. That way, it will not matter if the forecast is larger or smaller than the demand, as the error will be the same (Makridakis & Hibon, 2000). 2.2.1.4. Cumulative sum of forecast errors The three previous methods do not account for bias in the data. To do that, one can use the cumulative sum of forecast errors, using the equation: 𝐶𝐸𝐹= ∑𝑋𝑡− 𝑋𝑡 𝑇 𝑡=1 (2.7) If they wish to find the CEF at a given period, they must sum the errors up through that period. A good use for this measure is to evaluate planning efforts. If the forecast is regularly smaller than the real demand, the value of the CEF will grow higher and higher over time, indicating a systematic deficiency in the model (Krajewski et al., 2015).
8 2.2.1.5. Standard Deviation Finally, the standard deviation, σ, measures the likeliness that a forecast is accurate. This measure is often turned into a confidence score, and is granted by the following equation: σ=√∑((𝑋𝑡− 𝑋𝑡)−(𝑋− 𝑋) )2 𝑇 𝑡=1 𝑇−1 (2.8) 2.3. ARIMA MODEL During the beginning of the 20th century, a Russian statistician and economist, named Eugen Slutsky, and a British statistician, called George Yule, suggested the Autoregressive and Moving-Average processes. However, these practices would only reveal their power in the 1970s, when the Box- Jenkins method was introduced by George E. P. Box and by Gwilym Jenkins. An ARIMA model has three parameters: p (the number of auto-regressive terms), d (the number of times one must differentiate a series for it to become stationary), and q (the number of moving average terms) (Gujarati, 2003). To understand them further, various concepts must be introduced. 2.3.1. Autoregressive model (AR) The autoregressive model (AR) is a specific type of regression model where the dependent variable (in the PoC, sales, or transactions) depends on its past values. This implies that the forecast is necessarily related to previously observed values. This model is based on the concept of partial autocorrelation. An AR model of order p is given by the following equation: 𝑋𝑡=𝜙1𝑋𝑡−1+ 𝜙2𝑋𝑡−2+⋯+𝜙𝑝𝑋𝑡−𝑝+ 𝜔𝑡 (2.9) Just like before, 𝜔𝑡 stands for an unobservable white-noise sequence of independently and identically distributed random variables. 2.3.1.1. Autocorrelation and partial autocorrelation Autocorrelation is used to measure the linear relationship between values of the same variable at different times. The interval that separates two points in time is called the lag (Hyndman & Athanasopoulos, 2018; Montgomery et al., 2015). The autocorrelation coefficient at lag k, i.e., the coefficient of the correlation between the sales at time t, 𝑦𝑡, and the sales at another time period, 𝑦𝑡+𝑘, can be written as 𝜌𝑘= 𝐸[(𝑦𝑡−𝜇)(𝑦𝑡+𝑘−𝜇)] √𝐸[(𝑦𝑡−𝜇)2]𝐸[(𝑦𝑡+𝑘−𝜇)2] (2.10)
9 where 𝜇 is the mean of the data. The autocorrelation function is the collection of values of 𝜌𝑘, for k = 0, 1, 2, …. A correlation between a variable and itself is 1, so when k=0, it is assumed that the autocorrelation is 1. To get such a function, one must multiply both sides of the AR(p) function mentioned before by 𝑋𝑡−𝑘, which leads to 𝑋𝑡−𝑘𝑋𝑡= 𝜙1𝑋𝑡−1𝑋𝑡−𝑘+ 𝜙2𝑋𝑡−2𝑋𝑡−𝑘+⋯+𝜙𝑝𝑋𝑡−𝑝𝑋𝑡−𝑘+ 𝜔𝑡𝑋𝑡−𝑘 ⇔ ⇔ 𝑝𝑘= 𝜙1𝜌𝑘−1+ 𝜙2𝜌𝑘−2+⋯+𝜙𝑝𝜌𝑘−𝑝 ⇔ ⇔ 𝜙(𝐵)𝜌𝑘=0, 𝜙(𝐵)=1−𝜙1𝐵 − 𝜙2𝐵2−⋯−𝜙𝑝𝐵𝑝 (2.11) The set of equations one gets after replacing k with values 1, 2, … are called ad the Yule-Walker equations. Since the ACF does not depend on the scale of measurement of the time series, that makes it a dimensionless quantity. Besides this, the function is symmetric around 0, meaning 𝜌𝑘= 𝜌−𝑘. To better understand this concept, a particular example is shown. Below, one can see the plot showing the correlation between the total sales of store 6 in relation to its past values. Such plot is known as the Auto Correlation Function Plot (ACF Plot). As one can see, today’s sales have a big correlation with the number of sales from yesterday, from 6 days ago, from 7 and 8 days ago, and so on. To simplify, one can focus only on the first 4 higher correlations (lags 1, 6, 7, and 8). Assuming today is Friday, the past data that is relevant for today’s forecast is data from yesterday (Thursday), and data from last week’s Saturday, Friday, and Thursday. But yesterday’s values had been related to the previous day (Wednesday), and the week prior. This means that when one makes a prediction, that forecast will depend on all previous ones. A simple schema to help the understanding of the concept is shown in Figure 2.5. Figure 2.4 – ACF Plot for the total sales time series (2018 to 2020), in store 6
10 In the case of partial autocorrelation, it is only taken into consideration the days that affect directly today’s forecast. Implying that today’s value will depend on Thursday’s, Saturday’s, and Sunday’s. But, as one can see in Figure 2.6, the model will not look at the past values that influence each one of those. A simple correspondent schema is shown in Figure 2.7. Because of this, the PACF between 𝑦𝑡 and 𝑦𝑡+𝑘 becomes the autocorrelation amongst 𝑦𝑡 and 𝑦𝑡+𝑘 after adjusting for 𝑦𝑡−1, 𝑦𝑡−2, …, 𝑦𝑡−𝑘+1: 𝜌𝑗= 𝐸[(𝑦𝑡−𝜇)(𝑦𝑡+𝑘−𝜇) | 𝑦𝑡−1,…,𝑦𝑡−𝑘+1] √𝐸[(𝑦𝑡−𝜇)2 | 𝑦𝑡−1,…,𝑦𝑡−𝑘+1]𝐸[(𝑦𝑡+𝑘−𝜇)2|𝑦𝑡−1,…,𝑦𝑡−𝑘+1] (2.12) The autoregressive part of the ARIMA will then give different weights to past days, according to its correlations with the forecast. To find 𝑃𝑘𝑘,𝑘=1,…,𝑝 one can apply Cramer’s rule. If 𝑝<𝑘, 𝑃𝑘𝑘will equal 0, and the PACF of an AR(p) must cut down to zero after lag 𝑘=𝑝, where p is the order of the AR model. p can be thought of as the number of past days the model has to take into consideration. Wednesday Thursday Friday … Saturday Thursday Friday Saturday Figure 2.6 – PACF Plot for the total sales time series (2018 to 2020), in store 6 Figure 2.5 – Autocorrelation: daily influence in a forecast Figure 2.7 – Partial autocorrelation: daily influence in a forecast
11 2.3.2. Moving-average model (MA) The concept behind the moving-average model is like the one behind the autoregressive model. The MA part of the ARIMA model will consider the error resulting from previous forecasts. Again, assuming today is Friday. Yesterday, Saturday’s values were used to make today’s predictions. Unfortunately, those forecasts were below the real demand. That error will be inputted into today’s estimates. Just like in an autoregressive model, different weights are given to different errors, according to the correlations between the days. This time, the number of days from which errors should be considered is introduced by using the parameter q, known as the order of the MA model. For a general MA(q) process, the ACF must cut down to zero after the lag 𝑘=𝑞. The three most popular types of moving averages are: The Simple Moving Average (SMA), 𝑆𝑀𝐴= 𝐴1+𝐴2+⋯+𝐴𝑛 𝑛, (2.13) with 𝐴𝑛 being the average at the time period 𝑛, and 𝑛 being the number of time periods. The Weighted Moving Average (WMA), 𝑊𝑀𝐴= 𝐴1 × 𝑛+𝐴2×(𝑛−1)+⋯+𝐴𝑛 𝑛×(𝑛+1)2 ⁄, (2.14) The Exponential Moving Average (EMA), 𝐸𝑀𝐴𝑡= [𝑉𝑡×( 𝑠 1+𝑛)]+ 𝐸𝑀𝐴𝑡−1× [1−( 𝑠 1+𝑛)], (2.15) where 𝐸𝑀𝐴𝑡 is the EMA for the time period 𝑡, 𝑉𝑡 is the value for that time period, 𝐸𝑀𝐴𝑡−1 is the EMA for the time period 𝑡−1, 𝑠 is the smoothing factor, and 𝑛 is the number of data points. Usually, the smoothing factor follows the formula 2(𝑠𝑒𝑙𝑒𝑐𝑡𝑒𝑑 𝑡𝑖𝑚𝑒 𝑝𝑒𝑟𝑖𝑜𝑑+ 1) ⁄ (Alexander, 2008). 2.3.3. Integration (I) To use AR and MA models, it is necessary to have a stationary time series. This means that the average and the standard deviation of the time series points must be constant through time and that the series does not show the existence of seasonality. In the PoC, just in total transactions, 40 out of 48 stores did not have a stationary time series. Without transforming them into stationary ones, it would not be possible to generate predictions using the ARIMA model. Usually, to turn a nonstationary series into a stationary one, one uses the difference between each day and the day before, a calculation that is given by the equation 𝑍𝑡=𝑋𝑡+1− 𝑋𝑡. Sometimes, doing that one time is not enough. The model must know the number of differentiations it has to do so the series becomes stationary. That is exactly why the number of differentiations the model has to do so the series becomes stationary must be inserted into the model. That information is passed through the parameter d.
12 2.3.4. ARIMA pros and cons The ARIMA model makes very few assumptions and is very versatile. Furthermore, the model is iteratively selected based on the underlying data structure, having no need to arbitrarily assume a model prior to analysing the data (Ho & Xie, 1998). It is also found that when a time series is non-stationary, one of the most effective approaches to make demand forecasts is the ARIMA model (Box et al., 2015). Though ARIMA can be considered complicated in terms of theoretical concepts, it is such a wellknown model that many user-friendly software packages are now available to help data scientists build models. (Hot et al., 1998). Unfortunately, the model comes with more disadvantages other than its hard-to-understand theoretical basis, requiring a lot of data, and being computationally expensive. ARIMA models also struggle to predict changes in trend behavior. Still, they are known to perform well in short-run forecasts, most times, even better than other sophisticated structural models (O'Donovan, 1983). 2.4. FACEBOOK’S PROPHET ALGORITHM Besides using ARIMA to generate forecasts in the PoC, a model that is much more recent, Facebook’s Prophet, was also used. This algorithm was originally built to make predictions on internal projects. The code would later become open source (accessible to the general public), making it available to anyone who wishes to use it. (Taylor & Letham, 2018). Prophet is based on an additive regression model. Unlike ARIMA, which can be thought of in 3 different parts, this algorithm can be decomposed into 4 four parts. 2.4.1. Additive regression In a so-called simple regression (Equation 2.1), a statistician attempts to model the relationship between two variables, one of them being dependent (the one wished to be forecasted), and another being independent, often called explanatory. In the case of multiple regression, there are multiple explanatory variables (Gujarati & Porter., 2009). In multiple regression, it is assumed that the dependent variable is related to all the explanatory ones, but that those are not related to each other. The model is formulated as: 𝑦= 𝛽0+ 𝛽1𝑥1+ ⋯+ 𝛽𝑛𝑥𝑛+ 𝜀, (2.16) with 𝑦 being the dependent variable, 𝑥𝑖,𝑖=1,2,…,𝑛 being the explanatory variables, 𝛽𝑖,𝑖= 1,2,…,𝑛 being the regression coefficients, and 𝜀 being the error. In the real world, it is almost impossible to guarantee that the explanatory variables do not influence each other and that their individual influence on the dependent variable is linear. The additive
19 𝑠𝑡= 𝛾(𝑦𝑡−𝑙𝑡−1−𝑏𝑡−1)+(1−𝛾)𝑠𝑡−𝑚. Whereas, the multiplicative exponential smoothing of Holt-Winters is given by 𝑦𝑡+ℎ|𝑡= (𝑙𝑡+ℎ𝑏𝑡)𝑠𝑡+ℎ−𝑚(𝑘+1), 𝑙𝑡= 𝛼(𝑦𝑡𝑠𝑡−𝑚 ⁄)+(1−𝛼)(𝑙𝑡−1+𝑏𝑡−1) 𝑏𝑡= 𝛽∗(𝑙𝑡−𝑙𝑡−1)+(1−𝛽∗)𝑏𝑡−1 𝑠𝑡= 𝛾(𝑦𝑡(𝑙𝑡−1+𝑏𝑡−1) ⁄)+(1−𝛾)𝑠𝑡−𝑚 (2.25) (Hyndman & Athanasopoulos, 2018) The first, additive exponential smoothing of Holt-Winters, brought the best results when predicting demand for both hamburgers. The authors then adjusted their predictions using expert knowledge. Expert judgment came from three employees, who evaluated their colleagues in terms of experience. Between the three, a promotional factor, a store-reform factor, a special day factor (Children’s Day), and a climate factor were identified as possible influences on the restaurant’s demand. Independently, each employee gave their optimistic and pessimistic guess on how much they thought the factors influenced the meat request (on a percentage scale). Weights to their opinions were given, based on the expert’s experience, schooling, and company time, leaving the most qualified with the higher weight to their opinion. After using this qualitative measure to adjust the results obtained with the mathematical model, the previous error of 38% lowered to 10%.
20 3. METHODOLOGY 3.1. PROJECT INTRODUCTION As stated in 1.2, the client decided to explore (almost) all stores in Lisbon and Greater Lisbon and expected Noesis to build forecasting models to predict sales (in euros) and transactions (in units). Overall, 10 algorithms were to be developed, each looking to forecast: Total sales and transactions. Delivery sales and transactions (meals prepared and delivered by services like Uber Eats or Glovo). Drive sales and transactions (meals prepared and served in the drive-through). Eat-in sales and transactions (meals prepared and expected to be eaten inside the store). Take-away sales and transactions (meals prepared and bagged to be eaten outside the store). Two existing algorithms were used: ARIMA and Facebook Prophet. 3.1.1. Stores In total, after removing and joining stores together with the client, 48 stores (46 real and 2 mocks created from existing ones) from Lisbon and Greater Lisbon were analysed. These restaurants can be divided into three smaller groups: Free Stands, Malls, and Storefronts. Such distribution is shown below: Region Store Type Store ID 1 Lisbon Free Stand 25 38 39 46 Mall 2 3 19 22 26 32 45 Storefront 4 9 13 1 Encoded from the original store IDs.
21 20 21 29 31 34 40 43 100 Greater Lisbon Free Stand 10 11 15 16 23 27 28 30 33 35 36 37 42 Mall 5 6 7 8 12 14 17 18 41 101 Storefront 1 24 44 Table 1 – Distribution of stores per region and store type
22 3.1.2. Variables The variables provided by the company were (via the Noesis DAAI BI experts): Date. Store IDs (encoded in this report). Store names (occulted from this report). Store types (Free Stand, Mall, or Storefront). Sale type (Delivery, Drive, Eat-In, or Take-Out). Sales (in euros) for each day and sale type. Transactions (in units) for each day and sale type. The number of active campaigns (marketing campaigns, coupons, etc.) for each day and store. Besides these variables, the client also gave access to data related to media campaigns (investment in GRPs and awareness in percentage). Using intuition and some business knowledge, weather data was also added. 3.1.3. Development tools All of the code developed to produce forecasts was done using Python. The raw data was stored in Azure Blob Storage, transferred to Azure Databricks, where PySpark was used for reading. The produced results were then written back to Azure Blob Storage. After, the predictions were downloaded and sent to Noesis’ BI specialists, to be fed into a Qlik Sense dashboard, that allowed the client to view the forecasts in a more intuitively and interactively way. 3.1.4. Success metrics In order to test the developed algorithms, sales and transactions were predicted for the months of June, July, August, September, and October of 2020. These months were not chosen at random: since COVID-19 cases in Portugal were slowing down, most lockdown measures had been lifted at the time. The client understood that lockdown months were atypical, and more than likely, completely unpredictable. The option of removing June and October was kept open, as the first month was marked by lockdown measures being slowly taken down and the second by a visible increase in COVID-19 infections. Each algorithm was trained with the last X days. It was then used to predict the following 7 days. The forecast for the next day was added to the train set. Afterwards, X+1 days were used for training and used to predict the following 7. In the end, each date in the test set had 7 forecasts. To evaluate the model performance, a known metric, Mean Absolute Percentage Error was utilized, which allowed to form an idea of how far off the predicted were from the real values. Though MAPE is not always advised as a way to measure performance, the metric was kept, as it was much easier to explain to the client.
23 Given that each day has 7 forecasts, a day’s final MAPE is considered as being the average of the 7 forecasts. To evaluate the algorithm performance as a whole, those means were averaged out. 3.2. ROADMAP Together with the client, a 36-day roadmap was defined, predicting a project kick-off on April 5th, 2021, and a final presentation on May 25th. Most of the above roadmap was followed. The development and evaluation of forecasting algorithms and the evaluation of the results ended up being merged into just one stage. All the results and documentation were made available to the client on June 2nd, along with the Qlik Sense dashboard developed by the BI consultants. 3.3. DATA VALIDATION AND FUNCTIONAL CONSIDERATIONS To kick-off the Proof of Concept, a data validation stage had to take place, and some considerations had to be gathered, to solve some problems found during it: The days/sale types with negative sales and/or transactions were considered to have sales and/or null transactions. The days/sale types with sales but with no transactions were considered to have null sales. The days/sale types with transactions but with no sales were considered to have null transactions. Note that the above rules were only put in place after it was verified that those problems represented less than 1% of the total dataset. As mentioned before, two of the restaurants are mocks, made by joining data from two other stores: Data Analysis and Exploration Development and evaluation of forecasting algorithms Evaluation of results Qlik Sense dashboard development Testing and deploying the dashboard Intermediate meeting (13/April/2021) Intermediate meeting (11/May/2021) 6/April/2021 Kick-off (5/April/2021) 18/May/2021 25/May/2021 Figure 3.1 – Proof of Concept roadmap
24 Store 100 is a combination of two others. Different IDs represented the same store, but before and after remodeling. Because the store was renamed at the end of 2019, it had to be removed from the dataset. Since the testing period was in 2020, the second ID, for the purposes of this report, numbered 9999, was likewise deleted, as it would only have a short amount of data to train the model. A visualisation of store 9999’s total transactions can be found in 8.1. Store 101 is also a combination of two stores, one of them being store 18. Store 101 was a store in Greater Lisbon that was re-located in 2018. With the new building, the store ID was renamed to 18. Just like before, the first store was removed, has it did not have data for the testing period. However, store 18 was kept. This way, a comparison could be made between the two stores, to find out which had better performance: Store 101, with data from January 2018 to March 2020, or Store 18, with data from January 2019 to March 2020. Finally, one can interpret special days as being made up by: National holidays. St. Anthony's Day (because it is a holiday in Lisbon). Valentine’s Day, Mother’s Day, Father’s Day, and Children’s Day. It is important to denote that days with zero demand were not considered when calculating prediction errors. Together with the client, it was concluded that it was pretty much impossible to have unexpected days/sale types with no purchases. In all those cases, the client previously knows that a store will be closed. In such a big city like Lisbon, it is very improbable that the demand is indeed null merely due to customer behavior. Besides the days with negative sales and/or transactions, some restaurants had to be removed from the dataset, either because of their unique non-predictable behavior or due to lack of data. No other problems were found. 3.4. DATA ANALYSIS AND EXPLORATION Before beginning the development of algorithms, an analysis of the hundreds of time series used to feed the models was conducted. All the plots mentioned in the visual analysis can be found in 8 - Appendix. Because so many time series are visually similar in terms of trends and patterns, most of them have been omitted, being represented by the displayed ones. The majority of the time series plots have two distinct lines on them, representing the dates of March 17th, 2020, and June 3rd, 2020. Their addition is due to their importance in the evolution of the COVID-19 pandemic in Portugal. The first is when all non-essential services (including fast-food stores) were mandatorily closed. The second is when all non-essential services were free to open in total to customers again.
25 3.4.1. Time series visualisation To produce a visual analysis of the data, a Jupyter Notebook was created. The daily data was aggregated by sale type. Total sales and transactions were obtained by summing all the other sale type values. As expected, all the time series visualisations of eat-in and take-out sales and transactions (seen in appendixes 8.2, 8.3, 8.4, and 8.5) show null values between March and June of 2020. One can see there are many resemblances between free stands, malls, and storefronts. Though some show different patterns in terms of rises and falls in sales and transactions, none of them regain their previous eat-in behaviors after the first Portuguese lockdown. All stores went through a small period where sales and transactions slowly began to increase, only to start falling again closer to the end of the year. It is interesting to see that stores 4, 21, and 46, unlike all the others, have a drop in eat-in and take-out sales and transactions during the summertime. The common factor between all three stores is their close whereabouts to universities, showing that location can influence demand. When it comes to delivery, during the lockdown period, most stores have a huge rise in sales and transactions. Not only services like Uber Eats and Glovo are becoming more and more available, in some parts of the city, ordering through delivery was the only way to get a taste of fast food during the lockdown. Note, however, that as one can see in Figure 8.15 and Figure 8.17, some restaurants (8, 26, and 32) do not have any sales and transactions during the March to May lockdown. This null period comes from a business strategy. The company realized some stores were too close to others, and all deliveries could be sent out from one restaurant, instead of two. To reduce costs, some stores were completely shut down. For unknown reasons, as can be seen in Figure 8.14 and Figure 8.18, store 39 has a period between August and December of 2019 where sales and transactions rose to never-before-seen values. After December, however, the sales and transactions went back to their previous demand. Such an unexpected change in demand can be detrimental to the algorithms. As for the decrease in sales and transactions in store 21 (seen in Figure 8.16 and Figure 8.19), it is assumed that it happened for the same reason as the decrease in eat-in and take-out sales and transactions – the restaurant sits close to a university. Unlike stores 4 and 46, which are far from student residential locations, this surrounding area is mainly resided by the students themselves. As the university shut down, most students went back to their hometowns, causing the demand to decline. Concerning drive sales and transactions, all 19 stores that have it (the 17 free stands, mall 12, and storefront 34) showed an increase in sales during the lockdown. As can be seen in 8.8 and 8.9, all restaurants reach levels of demand higher than ever in their past. Though storefront 34 slowly regains its previous patterns, all the other restaurants go back to their previous behavior rather quickly. As one will be able to see later in this report, this return of known behavior will lead to much better prediction results than any of the other sale types. And finally, when it comes to total sales, as one can assume given the analysis above, all stores had a decrease in their sales and transactions during the year 2020. Stores like mall 3, which do not have a drive-through, and that were closed for delivery, have a null March to May period, making no
26 revenue during that time. With such an unstable period, the algorithms struggled to predict total values for most stores. 3.4.2. Outlier detection and analysis As mentioned in 2.5.1, detecting and treating outliers can improve a model’s predictions. Though Facebook’s Prophet is not as sensitive to outliers, the ARIMA model can be influenced by them, so it was decided that outliers should be detected and analysed, as they might impact predictions. One must keep in mind that outliers can provide useful information and should not always be removed. It was considered that outliers found to match special days should be kept so that the models received information on their demand effect. To identify such abnormal values Python’s Orion library was used. This package is very user-friendly and contains different detection techniques. For this particular analysis, the TadGAN (Time Series Anomaly Detection using Generative Adversarial Networks) model was chosen. This model was developed by Geiger et al. (2020) and combines deep learning approaches with GAN ones. Below, two tables are presented – each of them presents the average percentage of outliers in each time series for each sale type. The first relates to sales and the second to transactions. Sale Type Average percentage of outliers (after removing special days) Total 0.49% Delivery 0.65% Drive 0.72% Eat-In 0.43% Take-Out 0.63% Table 2 – Average percentage of outliers (after removing special days) for sales time series, for each sale type Sale Type Average percentage of outliers (after removing special days) Total 0.45% Delivery 0.52% Drive 0.57% Eat-In 0.29% Take-Out 0.65% Table 3 – Average percentage of outliers (after removing special days) for transactions time series, for each sale type Given that each store has a very low percentage of outliers that are not special days, and that most of those match the beginning of the March to May 2020 lockdown, no special treatment was applied, and all detected outliers were kept in the dataset.
27 3.5. DEVELOPMENT AND EVALUATION OF FORECASTING ALGORITHMS After the gathering of the functional considerations stated in 3.3 and an in-depth analysis of all time series, the next step became the development of forecasting algorithms. Due to research, and experience in previous similar use cases, it was decided two models should be tested and compared in terms of prediction performance. Before inserting any data into the algorithms, a division was done between train, validation, and test sets. The test dates had previously been defined by the client, as mentioned in 3.1.4. The developed pipeline should be tested by comparing forecasts and actual values for the months of June, July, August, September, and October of 2020. Eventually, the client hopes to invest in a system capable of generating daily predictions for the 7 following days. To mimic such a tool, 7 days of the test dates were removed. The historical data previous to those was used for training and validation. The first set was used to test different parametrizations, and the second to evaluate those. The best parameters (and most important external features, in Prophet’s case) were then employed to predict the 7 test days. The corresponding MAPE was stored, and the first of the 7 dates became part of the validation set. The first date of the validation set became part of the training set. The algorithm then predicted the following 7 days, and MAPE values were again stored. This process was repeated every day for the 5 testing months, and MAPE values were averaged out to evaluate performances. A diagram of this process is shown in Figure 3.2. 3.5.1. ARIMA As explained in 2.3, the ARIMA model needs three parameters (p, d, q) to predict future demand. Besides the fact that these parameters may change over time, it is impossible to analyse over 400 time series manually. Because of that, the model was implemented using Python’s pmdarima package. This library applies an Auto ARIMA model, automatically finding the optimal p, d, and q values. Since the PoC timeline was limited, it was decided to randomly choose 3 stores (a free stand, a mall, and a storefront), a prediction segment, and a test month, to examine how often the p, d, and q values must be reviewed. The chosen stores were numbers 26, 34, and 39; the segment was total transactions, and the test month was October. Below, the results of various tests can be consulted. Figure 3.2 – System validation diagram Iteration 1 Iteration 2 Iteration k … … … … Training set Validation set Test set Dataset
28 Store Daily Every 7 days Every 10 days MAPE Time MAPE Time MAPE Time 26 13.77% 8.3 h 13.87% 1.6 h 14.32% 30 min 34 12.08% 5.6 h 12.06% 36 min 12.14% 14 min 39 14.24% 6.2 h 8.6% 52 min 9.29% 36 min Store Every 15 days Every 20 days Every 30 days MAPE Time MAPE Time MAPE Time 26 14.03% 31 min 13.95% 21 min 14.03% 13 min 34 11.70% 25 min 12.28% 16 min 12.29% 7 min 39 8.45% 32 min 8.96% 15 min 9.29% 16 min Table 4 – Running time and average MAPE when reviewing ARIMA’s parameters every X days Though the mall (26) had better performance when replacing the p, d, and q values daily, the free stand (39) and the storefront (34) had better performance when doing it every 15 days. Note that the malls suffered a bigger impact on their trend than the other 2 store types due to the Portuguese lockdown measures, making their parametrization more complex. Given the limited time, it was decided to review parameters every 15 days for every store, no matter which store type it belonged to. Knowing the model’s parameters must be reviewed every 15 days, it was also important to test different lengths for the validation period. Usually, the validation period is the one immediately before the testing one. However, the team has found that in forecasting projects, validating parameters in the dates of the previous year that correspond to the test set dates (i.e., validating parameters in the 1st to 15th of October of 2019 to test the 1st to the 15th of October of 2020) sometimes brings better results. Given the change in behavior from 2019 to 2020 in almost all time series, and with no time to review them all, the second option was discarded. Therefore, there was an attempt to use a 10-fold method, where every 15 days, the parameters were tested in 10 different periods, and the combination that led to the lowest average error was chosen. Yet, the predictions were taking too long to generate, and the 10-fold had to be reduced to a 5-fold. Finally, external variables were added to the model. The ones related to the weather did not improve the results. The others, like active campaigns, investments, and awareness, were impossible to add to the model. Python’s ARIMA model is not capable of generating forecasts if the external variables present the same value throughout the testing period. For example, as one can see in Table 5, in the first week of august, store 39 has the same values for active campaigns. Date Store Number Sale Type Transactions Sales Active Campaigns Awareness Investment 8/1/2020 39 Drive 664 5725.347 3 59 646 8/2/2020 39 Drive 608 5318.283 3 59 646 8/3/2020 39 Drive 591 4474.282 3 60 486 8/4/2020 39 Drive 551 4275.856 3 60 486 8/5/2020 39 Drive 634 4758.08 3 60 486
35 Greater Lisbon Mall 13.12% 12.11% 22.43% 19.44% 15.85% 12.17% Greater Lisbon Store front 12.44% 11.37% 14.52% 12.60% Lisbon All 12.32% 10.87% 15.65% 14.23% 8.46% 6.82% Greater Lisbon All 10.88% 9.93% 20.28% 17.79% 8.82% 7.09% All Free Stand 9.04% 8.05% 18.36% 16.28% 8.33% 6.71% All Mall 13.02% 11.99% 20.03% 17.62% 15.85% 12.17% All Storefront 12.99% 11.39% 15.34% 13.91% 8.41% 7.14% Table 10 – Average MAPE for each region and store type in total, delivery and drive sales and transactions Table 11 – Average MAPE for each region and store type in eat-in and take-out sales and transactions To see the distribution of the MAPE by day of the week, the plot of Figure 4.1 was generated. As one can see, the hardest day of the week to predict is Monday. In all sale types, Monday performs the worst between all weekdays, with take-out sales showing the highest MAPE. Regarding the most predictable weekday, the answer is not as simple. Eat-in sales present lower forecast errors on Eat-In Take-Out Region Store Type Sales Transactions Sales Transactions Lisbon Free Stand 15.59% 12.05% 26.84% 23.09% Lisbon Mall 25.03% 16.50% 22.08% 17.67% Lisbon Storefront 25.88% 14.26% 21.87% 18.08% Greater Lisbon Free Stand 15.59% 13.64% 23.80% 20.14% Greater Lisbon Mall 35.54% 18.85% 18.65% 15.36% Greater Lisbon Storefront 16.74% 14.02% 17.56% 15.35% Lisbon All 23.74% 14.57% 22.84% 18.86% Greater Lisbon All 23.66% 15.76% 21.14% 17.72% All Free Stand 15.59% 13.26% 24.52% 20.83% All Mall 31.22% 17.88% 20.06% 16.31% All Storefront 23.92% 14.21% 20.95% 17.49%
36 Tuesdays and delivery transactions on Thursdays. The rest show better performance during the weekend. A short analysis on the MAPE distribution by month was also conducted, and, as can be comprehended by looking at Figure 4.2, June and October were the two worst-performing months in all prediction segments. As mentioned in 3.1.4, the client had opened the possibility of removing the months of June and October. To check their impact on the average errors, new calculations were made after their removal. The results can be seen in Table 12. 0 5 10 15 20 25 30 35 40 45 50 Monday Tuesday Wednesday Thursday Friday Saturday Sunday Average MAPE Day of the week Sales - Total Transactions - Total Sales - Delivery Transactions - Delivery Sales - Drive Transactions - Drive Sales - Eat-In Transactions - Eat-In Sales - Take-Out Transactions - Take-Out Figure 4.1 – MAPE distribution by day of the week 0 5 10 15 20 25 30 35 40 45 50 June July August September October Average MAPE Month Sales - Total Transactions - Total Sales - Delivery Transactions - Delivery Sales - Drive Transactions - Drive Sales - Eat-In Transactions - Eat-In Sales - Take-Out Transactions - Take-Out Figure 4.2 – MAPE distribution by month
37 Sale Type Sales Transactions Total 9.6% 8.6% Delivery 15.8% 14.2% Drive 7.5% 6.3% Eat-In 18.8% 11.7% Take-Out 18.7% 15.8% Table 12 – Average MAPE for each sale type, for the months of July to September 2020 Removing the months of June and October obviously improved all results, corroborating the theory that the COVID-19 measures and case numbers probably influence the demand in the stores. Concerning algorithm distribution, there was not one that overshadowed the other. As one can see in Table 13, ARIMA seems to produce better results in more disruptive segments. Assuming demand will normalize in the next few years, Prophet might become more important in producing the franchise’s forecasts. Sale Type Sales Transactions ARIMA Prophet ARIMA Prophet Total 26 13 38 11 Delivery 13 32 9 36 Drive 6 13 8 11 Eat-In 34 15 46 3 Take-Out 23 26 32 17 Table 13 – Number of times each algorithm showed better performance in each prediction segment Given the fact that the algorithms’ performances were highly affected by the COVID-19 pandemic, the client was very interested in seeing a present-day performance. It was agreed that the Proof of Concept would expand for a couple of more months, with the team generating predictions every week and feeding them to the Qlik Sense dashboard for the client’s usage. Weekly average MAPE can be consulted in 8.12. The overall performance can be seen below, in Table 14. It is important to note that some days presented problems in their data. For example, store 14 reaches over 2000€ in eat-in sales on July 16th but makes less than 1€ in the two following days. Other restaurants had the same problem, leading to the removal of days 10, 11, 17, and 18 of July from the error calculations. Sale Type Sales Transactions Total 12.4% 10.7% Delivery 19.1% 16.1% Drive 11.5% 9.3% Eat-In 21.5% 19.9% Take-Out 25.7% 20.8% Table 14 – Average MAPE for each sale type, from May 29th until July 16th
38 At the end of 2020, a new lockdown measure was put in place – most stores and restaurants should be closed before 1 pm every weekend. Previously, Saturday and Sunday used to show the lowest forecast errors in almost every segment. To see if the weekends continued their predictability, a new visual analysis was conducted. Unlike before, the plot of the MAPE distribution by day of the week (Figure 4.3), shows that weekends became the most un-predictable weekdays in the majority of the segments. To see how much those days impacted the outcomes, new MAPE values were calculated, after removing the weekends. Results can be seen in Table 15. Sale Type Sales Transactions Total 12.1% 9.9% Delivery 18.7% 15.6% Drive 10.9% 8.4% Eat-In 17.2% 14.7% Take-Out 24.8% 19.3% Table 15 – Average MAPE for each sale type, from May 29th until July 16th (excluding weekends) As expected, the removal of the weekend forecasts did improve the results. Again, it seems like the different lockdown measures put in place definitely impacted demand, both in 2020 and in 2021. Even though the Qlik Sense dashboard development is out of the scope of the internship, it is considered an important part of the project, as it became the way for the client to visualise all the work done by the Data Science consultants. A snapshot of the dashboard, developed by the Business Intelligence specialists, can be seen in 8.13. 0 5 10 15 20 25 30 35 40 45 50 Monday Tuesday Wednesday Thursday Friday Saturday Sunday Average MAPE Day of the week Sales - Total Transactions - Total Sales - Delivery Transactions - Delivery Sales - Drive Transactions - Drive Sales - EatIn Transactions - EatIn Sales - TakeOut Transactions - TakeOut Figure 4.3 – MAPE distribution by day of the week
39 5. CONCLUSIONS The forecasting project kicked off in April 2021 and began with a dive into the business strategies of the franchise. Various meetings with the client allowed Noesis to align expectations, and to understand their goals. It was defined from the beginning that the long-run objective was to have a system capable of making forecasts for the company’s demand. To prove such a concept, 10 prediction segments were chosen (Total/Delivery/Drive/Eat-in/Take-Out x Sales/Transactions), and 48 stores from Lisbon and Greater Lisbon were selected. The process opened with a data analysis phase, which quickly led to the realization that the COVID-19 pandemic would more than likely complicate the forecasts. Lots of time series seemed disruptive, with long periods of nonexistent demand. Two algorithms were tested (ARIMA and Facebook’s Prophet), and it was expected that one would be chosen to produce all future forecasts. Since both showed better results in different segments, a hybrid system was created. Predictions were then sent to the BI experts and incorporated into a dashboard. As the process went on, the client began feeling more curious about how the system would behave in the present time, so an “after-PoC” stage was conducted, with forecasts being generated each week, from the end of May until mid-July 2021. The internship allowed the usage of many concepts learned in the first year of the Master’s in Data Science and Advanced Analytics. The whole system was built in Databricks, a software that became familiar in the Big Data Analytics course. The forecasting algorithms, especially ARIMA, had been introduced in the Statistics course, and the programming side of the project joined knowledge from various other courses. New knowledge was acquired, especially when it came to the business operations, both of Noesis, as a consulting company, and the client’s franchise, as a fast-food chain. New algorithms were explored along with different software. Overall, the experience fully related to the Master’s concepts and opened the door to future opportunities.
40 6. LIMITATIONS AND RECOMMENDATIONS FOR FUTURE WORKS Though the proof of concept ended on a successful note, there is still a lot of space for improvement. The biggest setback was time, which happened mainly due to the fact that all code was developed using solely Python. The algorithm packages that were used are yet to be adapted for PySpark data frames, making the processes much slower. In the future, the team should look to over-ride noncompatible methods by adapting the packages for PySpark data frames. This procedure will allow for much faster development, as Databricks is built on top of Spark, and can automatically parallelize code. If the PoC moves on to a project to be deployed, an engineering solution will have to be implemented to make the complete process automatic. The client will be able to choose between an on-premises solution (shown in Figure 6.1) or a cloud solution (shown in Figure 6.2). Moreover, it is advised that in future developments, the outlier detection technique be reviewed, and that outlier treatment should be considered. Normalization of numerical variables should also be evaluated. Besides, more business knowledge is important - for instance, the work around external variables is considered incomplete, as many more variables can impact demand: school calendars, the distance between stores, football data (derbies might influence delivery demand, and even all sale types in stores close to stadiums). The hypothesis of adding them to the ARIMA model must also be reconsidered. Data movement Data transformation Raw data Processed data Forecasts INGEST STORE PREP AND TRAIN SERVE Ingesting system Communication system ModelOps IA External sources Nonrelational data Database Deploy Models Temporary storage system Database Visualisations External software Data preparation Forecasts Model evaluation Model training Model development Feature Engineering Feature selection Parameterisation Figure 6.1 – Proposed on-premises architecture Figure 6.2 – Proposed cloud architecture
41 So far, time series were fed into the algorithms one by one, not taking into account the other sale types sales, and transactions. The possibility of considering other time series when forecasting another should be investigated. New algorithms can be used, such as XGBoost Regressor. Until now, the two algorithms were generating forecasts for all prediction segments. It is possible that each algorithm works better for a specific type of store. Clustering restaurants might reduce the number of forecasts, as the models can possibly be assigned to each cluster. This process, however, must also be automatized, as stores will continue to open and close. Finally, and most significantly, it is believed that the results will only improve when the pandemic situation has either stabilized, or the day-to-day of the Portuguese people goes back to what it was before. Until the routines of customers become firm, and lockdown measures stop being reviewed so often, it is not expected that the forecasting errors diminish significantly.
42 7. BIBLIOGRAPHY Blecher, L. (2004). Using forecasting techniques to predict meal demand in Title IIIc congregate lunch programs. RESEARCH: RESEARCH AND PROFESSIONAL BRIEFS, 104(8), 1281-1283. https://doi.org/10.1016/j.jada.2004.05.209 Box, G. E. P., Jenkins, G. M., Reinsel, G. C., & Ljung, G. M. (2015). Time Series Analysis: Forecasting and Control (5th ed.). John Wiley and Sons Inc. Brockwell, P. J., & Davis, R. A. (2002). Introduction to Time Series and Forecasting (2nd ed). Springer Nature. https://doi.org/10.1007/b97391 Alexander, C. (2008). Moving average models for volatility and correlation, and covariance matrices. Handbook of finance, 3. Wiley Press. Geiger, A., Liu, D., Alnegheimish, S., Cuesta-Infante, A., & Veeramachaneni, K. (2020). TadGAN: Time Series Anomaly Detection Using Generative Adversarial Networks. BigData-2020. In Proceedings of IEEE International Conference on Big Data. https://arxiv.org/pdf/2009.07769.pdf Gujarati, D. N., & Porter, D. C. (2009). Basic Econometrics (5th ed). McGraw-Hill. Gujarati, D. N. (2003). Basic Econometrics (4th ed). McGraw-Hill. Harvey, A. C., & Shephard, N. (1993). Structural time series model. Handbook of Statistics, 11, 261– 302. Harvey, A., & Peters, S. (1990). Estimation procedures for structural time series models. Journal of Forecasting, 9(2), 89-108. https://doi.org/10.1002/for.3980090203 Ho, S. L., & Xie, M. (1998). The Use of ARIMA Models for Reliability Forecasting and Analysis. Computers & Industrial Engineering, 35(1-2), 213-216. https://doi.org/10.1016/S0360- 8352(98)00066-7 Hyndman, R. J., & Athanasopoulos, G. (2018). Forecasting: principles and practice. (2nd ed). OTexts: Melbourne, Australia. https://OTexts.com/fpp2 Krajewski, J., Ritzman, B., & Malhotra, M. (2015). Operations Management: Processes and Value Chains (11h ed). Pearson Prentice Hall. Lasek, A., Cercone, N., & Saunders, J. (2016). Restaurant Sales and Customer Demand Forecasting: Literature Survey and Categorization of Methods. Smart City 360° – First EAI International Summit: Revised Selected Papers, Bratislava, Slovakia and Toronto, Canada, 479-491. https://doi.org/10.1007/978-3-319-33681-7_40 Liu, L., Bhattacharyya, S., Sclove, S. L., Chen, R., & Lattyak, W. J. (2001). Data mining on time series: an illustration using fast-food restaurant franchise data. Computational Statistics & Data Analysis, 37(4), 455-476. https://doi.org/10.1016/S0167-9473(01)00014-7
43 Makridakis, S., & Hibon, M. (2000). The M3-competition: results, conclusions and implications. International Journal of Forecasting, 16(4), 451–476. https://doi.org/10.1016/S0169-2070(00)00057- 1 Meneghini, M., Anzanello, M., Kahmann, A., & Tortorella, G. (2018). Quantitative demand forecasting adjustment based on qualitative factors: case study at a fast food restaurant. Systems & Management, 13, 68-80. https://doi.org/10.20985/1980-5160.2018.v13n1.1188 Miller, J. L., McCahon, C. S., & Bloss, B. K. (1990). Food Production Forecasting with Simple Time Series Models. Journal of Hospitality & Tourism Research, 14(3), 9–21. https://doi.org/10.1177/109634809101400303 Montgomery, C. D., Jennings, C. L., & Kulahci, M. (2015). Introduction to Time Series Analysis and Forecasting (2nd ed). John Wiley & Sons Inc. Pollock, D. S. G. (1999). A Handbook of Time Series Analysis, Signal Processing and Dynamics. (1st ed). Academic Press. https://doi.org/10.1016/B978-0-12-560990-6.X5000-3 Schimek, M. G., & Turlach, B. A. (1998). Additive and generalized additive models: A survey. SFB 373 Discussion Paper (No 1998,97). Silver, E. A., Pyke, D. F., & Peterson, R. (1998). Inventory Management and Production Planning Scheduling. (3rd ed). John Wiley & Sons Inc. Taylor, S. J., & Letham, B. (2018). Forecasting at Scale. The American Statistician, 72(1), 37-45. https://doi.org/10.1080/00031305.2017.1380080 Wallström, P., & Segerstedt, A. (2010). Evaluation of forecasting error measurements and techniques for intermittent demand. International Journal of Production Economics, 128(2), 625-636. https://doi.org/10.1016/j.ijpe.2010.07.013 Zhang, G. P. (2003). Time series forecasting using a hybrid ARIMA and neural network model. Neurocomputing, 50(17), 159–175. https://doi.org/10.1016/S0925-2312(01)00702-0
44 8. APPENDIX 8.1. TIME SERIES OF TOTAL TRANSACTIONS FROM 2018 TO 2020, IN STORE 9999 8.2. TIME SERIES OF EAT-IN SALES FROM 2018 TO 2020 Figure 8.1 – Time series of total transactions from 2018 to 2020, in store 9999 Figure 8.2 – Time series of eat-in sales from 2018 to 2020, in free stands 30 and 46 Figure 8.3 – Time series of eat-in sales from 2018 to 2020, in mall 3 Figure 8.4 – Time series of eat-in sales from 2018 to 2020, storefronts 1 and 4
51 8.12. AFTER-POC WEEKLY RESULTS Table 16 – Average MAPE for each sale type, from May 29th to June 5th Table 17 – Average MAPE for each sale type, from June 6th to June 12th Table 18 – Average MAPE for each sale type, from June 13th to June 19th Table 19 – Average MAPE for each sale type, from June 20th to June 26th Sale Type Sales Transactions Total 16.0% 13.0% Delivery 21.6% 18.4% Drive 11.5% 8.3% Eat-In 19.3% 15.9% Take-Out 27.8% 21.0% Sale Type Sales Transactions Total 16.2% 12.5% Delivery 23.3% 18.4% Drive 11.8% 8.5% Eat-In 22.7% 14.7% Take-Out 29.7% 22.2% Sale Type Sales Transactions Total 12.9% 10.7% Delivery 18.4% 16.0% Drive 12.4% 10.1% Eat-In 23.0% 19.0% Take-Out 25.7% 19.8% Sale Type Sales Transactions Total 11.0% 11.9% Delivery 19.5% 16.4% Drive 10.7% 11.0% Eat-In 20.8% 22.3% Take-Out 23.2% 20.7% Sale Type Sales Transactions Total 11.5% 10.5% Delivery 18.7% 16.7% Drive 11.8% 8.5%
52 Table 20 – Average MAPE for each sale type, from June 27th to July 3rd Table 21 – Average MAPE for each sale type, from July 4th to July 9th Table 22 – Average MAPE for each sale type, from July 12th to July 16th 8.13. QLIK SENSE DASHBOARD 2 2 Anything that could be used to identify the franchise (including the color scheme) has either been altered or completely omitted. Eat-In 28.3% 30.1% Take-Out 24.8% 21.7% Sale Type Sales Transactions Total 8.5% 8.2% Delivery 15.3% 12.7% Drive 12.3% 10.1% Eat-In 19.5% 22.4% Take-Out 22.7% 19.6% Sale Type Sales Transactions Total 8.0% 6.4% Delivery 14.1% 12.3% Drive 9.4% 7.9% Eat-In 14.8% 14.4% Take-Out 25.1% 20.4% Figure 8.32 – Qlik Sense dashboard developed by Noesis’ DAAI (BI) specialists