## 5 Preliminary Testing  
The model has been validated through tests conducted on the prediction of several products that catch company interest. Figure 2a,b show the prediction of the sale of a given product in a specific branch performed, respectively, by GBR and XGBR. The prediction data (orange plot) are compared with the real values (blue plot). The qualitative comparison of Figure 2a,b shows greater accuracy of the XGBoost model. The suitability of this last method is confirmed by the analysis carried out by the main accuracy metrics. Figure 2: Cont. In detail, the metrics [44; 45] used to evaluate the accuracy of the two developed models are the following:  
\[\text{MSE}=\frac{1}{\text{n}}\sum_{i=1}^{\text{n}}(y_{i}-\hat{y}_{i})^{2}\]  
\[\text{MAE}=\frac{1}{\text{n}}\sum_{i=1}^{\text{n}}\lvert y_{i}-\hat{y}_{i}\rvert\]  
\[\text{MAPE}=\frac{1}{\text{n}}\sum_{i=1}^{\text{n}}\Bigl{\lvert}\frac{y_{i}- \hat{y}_{i}}{y_{i}}\Bigr{\rvert}100\%\]  
\[\text{WAPE}=\frac{1}{\text{n}}\frac{\sum_{i=1}^{\text{n}}\lvert y_{i}-\hat{y}_{ i}\rvert}{\sum_{i=1}^{\text{n}}\lvert y_{i}\rvert}100\%\]  
WAPE (weighted absolute percentage error) is very important in the calculation of the forecast error, in fact it is the absolute error averaged over the real requested quantity [46]. Therefore, compared to MAPE, WAPE allows the estimation in a more balanced way of the impact of the prediction on sales and profits [47; 48]. MAPE is a good metric for measuring forecast errors, but it is not indicative in the case in which sales are intermittent or assume values close to zero. WAPE is a metric that overcomes this problem by weighting the error on total sales. Figure 3 shows the values of the accuracy obtained for the test reported in Figure 2. The XGBoost model allows more accurate results to be obtained. Table 1 summarizes the meaning and values of the main hyperparameters that were used during the run of Figure 2b. These values were automatically tuned by using GridSearchCV. Regarding the parameters of the GBR model, the following choices were made: n_estimators = 500, max_depth = 4, min_samples_split = 2, learning_rate = 0.01. \begin{table}
\begin{tabular}{c c c} \hline \hline
**Hyperparameter** & **Value** & **Meaning** \\ \hline Eta (learning\_rate) & 0.1 & Shrinkage coefficient of each tree \\ N\_estimators & 215 & Number of estimators \\ Max\_depth & 4 & Maximum depth of the tree \\ Colsample\_bytree & 0.9 & Subsample ratio of columns for each tree \\ Gamma & 0 & Minimum loss function reduction to make new tree-split \\ Min\_child\_weight & 1 & Minimum sum of weights in a child \\ Alpha & 0 & L1 regularization term on leaf weights \\ Lambda & 1 & L2 regularization term on leaf weights \\ \hline \hline \end{tabular}
\end{table} 
Table 1: Setting of hyperparameters for the developed XGBoost model. Figure 2: Predictive model test for a specific product and branch: (**a**) Gradient Boosting; (**b**) XGBoost. A second test was performed on a new product recently launched in two different stores, which stock up in the same warehouse, see Figure 4 for the test results. The predictions carried out by the XGBoost model are now less accurate than in the previous test, as the training dataset is less rich. The model fails to predict sales trends well. Figure 4c shows the results of the prediction performed with the XGBoost model trained on data collected from both stores. In this case, the prediction is more accurate. For completeness, Figure 5 also shows the comparison with the prediction reached using the GB model trained on the same assembled dataset. As in the test shown in Figure 2, the XGBoost model proves to be performing better than the GB model. In Figure 5, the accuracy metrics confirm the considerations made for this second test. Figure 3: Accuracy metrics referred to the validation test of the GB and XGBoost models: MAPE (**a**); MSE, MAE and WAPE (**b**).