# Sales Forecasting with LSTM, Custom Loss Function, and Hyperparameter Optimization: A Case Study
## 1 Introduction  
Currently, the field of forecasting has grown so much that companies have started to have a great interest in developing sales forecasting models that help them build business strategies in areas such as production, transportation, and the supply chain, among others [1; 2]. These forecasting models facilitate identifying market opportunities and anticipating possible challenges [3], allowing business tactics to be adapted effectively [4]. Additionally, forecasting is essential for the efficient allocation of resources because it helps prioritize investments and optimize the use of assets [5]. Furthermore, sales forecasting provides valuable information for designing advertising campaigns and promotions that reach the right audience at the right time [6]. It also influences logistics by determining product flows and the storage capacity needed to keep the supply chain. Moreover, efficient inventory management and supply chain optimization are critical to any company's increasing operational and financial success rate; they are especially relevant in sectors such as goods, services, industry, manufacturing, logistics, transportation, the automotive sector, and e-commerce, where fluctuations in demand and seasonality can represent significant challenges [7]. In this sense, trends and forecasts are essential to addressing the inventory management problem. [PERSON] and [PERSON] [8] emphasized the importance of sales forecasting accuracy for businesses, enabling proper resource allocation, efficient inventory management, and streamlined operations. Thus, analyzing historical sales trends will allow the identification of demand patterns, such as seasonality or sales cycles. The above will helppredict when and in what quantity products are needed, allowing industries to anticipate demand peaks and adjust their inventory levels accordingly, avoiding product shortages or excessive purchases at unnecessary times. Diverse papers can be found on the state-of-the-art related to forecasting, mainly using so-called Recurrent Neural Networks (RNNs). These networks have emerged as essential tools in machine learning, especially when processing sequential data. Their ability to maintain and use information about past events makes them particularly useful for diverse applications that depend on temporal patterns [9]. An example is [10], where [PERSON] et al. addressed the prediction of hydrological time series, using a Recurrent Neural Network (RNN) to forecast monthly river flows. The authors conducted a comparative study of a multilayer perceptron network and an RNN. The study showed that the RNN outperformed the perceptron network by achieving greater accuracy in less training time. The paper concluded that the superior accuracy of the RNN was due to its ability to capture and utilize the temporal dependencies present in hydrological data. In [11], [PERSON] and [PERSON] used an RNN to predict ocean waves. The RNN could predict waves at intervals of 3, 6, and 12 h. Thus, the results proved to be promising forecasts, showing correlation coefficients of 0.95 for 3 h, 0.90 for 6 h, and 0.87 for 12 h. Based on the forecasts obtained, offshore operations could be carried out more safely and efficiently, benefiting activities such as drilling, merchant ship navigation, and coastal construction. Similarly, in [12], [PERSON] et al. proposed an approach for predicting hourly prices in the electricity field based on similar days; the authors developed and trained an RNN model using backpropagation for their proposal. They also designed a method to select days with similar characteristics, to improve the price forecast. MAPE and FMSE were used to evaluate the performance of the RNN model. According to the results obtained, the authors identified that \"demand\" is the most crucial variable in the price of electricity and concluded that the RNN-based algorithm effectively solved the volatility problem in the price curves of the US-regulated electricity market.