# Sales Forecasting with LSTM, Custom Loss Function, and Hyperparameter Optimization: A Case Study
## 5 Conclusions  
Loss management is a crucial aspect that directly impacts the profitability and stability of any company. The consequences of losses go beyond the financial aspect; they also affect the company's reputation, customer confidence, and employee morale. Thus, although losses are inevitable in virtually any context, their impact and frequency can be significantly reduced by implementing accurate and efficient forecasting strategies. Consequently, researchers have developed artificial intelligence techniques to perform forecasting tasks more efficiently and in less time than it would take to perform the process using traditional methods. \begin{table}
\begin{tabular}{c c c c} \hline
**Product** & **ISFC** & **BSFC** & **Improvement** \\ \hline
1 & 947 & 892 & 5.81\% \\
2 & 2918 & 1838 & 37.01\% \\
3 & 4102 & 954 & 76.74\% \\
4 & 1910 & 1272 & 33.40\% \\
5 & 3556 & 2110 & 40.66\% \\ \hline \end{tabular}
\end{table} 
Table 10: Genetic algorithm found cost. In this paper, we designed an LSTM network to forecast sales of a lumber mill in Tamaulipas, Mexico. The LSTM network was integrated with three LSTM layers with a dropout rate to prevent overfitting of the network and improve its ability to capture temporal dependencies and patterns in the sales data of the lumber mill products, thus optimizing its performance. Furthermore, we designed a custom loss cost function, which allowed a more precise evaluation of the performance of the LSTM network, including the particular needs of the data instances and the problem addressed in this paper. Similarly, we designed and implemented a genetic algorithm for the optimization of the hyperparameters of the LSTM network. The experimental results show that the proposal of the personalized cost function, the structure of the LSTM network, and the genetic algorithm used for optimizing the LSTM hyperparameters contributed actively and crucially to improving the accuracy and efficiency of sales forecasts for the lumber mill products. Thus, the results obtained show an improvement for all the products considered in this paper compared with the results of the first execution of the genetic algorithm for optimizing the LSTM network, which reached an average improvement of approximately 38.73%. The results show that the lowest relative variation was found in product 1, with a value of 5.81%, and the most significant variation was found in product 3, with approximately 76.74%, which indicates that the genetic algorithm is suitable for optimizing the hyperparameters of the LSTM network. Finally, as future work, we will consider testing other genetic operators and evolutionary algorithms for optimizing the hyperparameters of the LSTM network and, additionally, testing other variants of the LSTM network structure and proposing new customized functions that allow companies to consider other aspects of importance in addition to the storage and production costs. Conceptualization, A.H.G.-R. and L.J.G.-d.-A. ; methodology, L.A.H.-B. ; software, A.H.G.-R. and H.A.H.-M.; validation, A.H.G.-R., H.A.H.-M. and L.A.H.-B. ; formal analysis, A.H.G.-R. and R.P.-R.; investigation, L.J.G.-d.-A. ; resources, R.P.-R.; data curation, A.H.G.-R., writing--original draft preparation, A.H.G.-R. and R.P.-R.; writing--review and editing, H.A.H.-M. and L.A.H.-B. ; visualization, L.A.H.-B. ; supervision, A.H.G.-R. and L.J.G.-d.-A. ; project administration, A.H.G.-R., L.J.G.-d.-A. and R.P.-R.; funding acquisition, R.P.-R. All authors have read and agreed to the published version of the manuscript. This research received no external funding. The APC was funded by the Autonomous University of Tamaulipas. Not applicable. The benchmark instances for this study are available at [[https://github.com/ahgaricar/Lumber_Mill_Instances](https://github.com/ahgaricar/Lumber_Mill_Instances)]([https://github.com/ahgaricar/Lumber_Mill_Instances](https://github.com/ahgaricar/Lumber_Mill_Instances)), accessed on 20 September 2024. A.H.G.-R. would like to acknowledge CONAHCyT Mexico for the SNII salary award.