# Augmented Data and XGBoost Improvement for Sales Forecasting in the Large-Scale Retail Sector
## 2 Methodology: Platform Design and Implementation and AD Approach
### Platform Design and Implementation
Unless the customer makes a large number of purchases in the training period, it is difficult to acquire an accurate prediction of the products they will buy. To overcome the lack of statistics on customers who are not very loyal, customers were grouped into clusters. Clusters are segments or groups of people with similar habits of recency and frequency. This segmentation allows for the increase of the statistics available as the data of the whole group are analyzed to predict what the whole group will buy. Subsequently, other algorithms could be used to distribute the predicted sales among the customers belonging to that cluster. Clustering is based on the calculation of the quintiles (20%, 40%,... 100%) of the cumulative frequency of recency (number of days since the last order) and frequency (total number of orders in the last 90 days) for each customer who made purchases on the analysis day. The quantiles were calculated over the last 90 days. On the basis of the recency and frequency values with respect to the quintile values, the following scores were defined for the recency (\(R\)) and for the frequency (\(F\)) which are associated with each customer:  
\[R=\left\{ \begin{array}{l}5\;for\;first\;quittile\;(0-20\%)\\ 4\;for\;second\;quittile\;(20-40\%)\\ 3\;for\;third\;quittile\;(40-60\%)\\ 2\;for\;fourth\;quittile\;(60-80\%)\\ 1\;for\;fifth\;quittile\;(80-100\%)\\ \end{array} \right.\]  
\[F=\left\{ \begin{array}{l}1\;for\;first\;quittile\;(0-20\%)\\ 2\;for\;second\;quittile\;(20-40\%)\\ 3\;for\;third\;quittile\;(40-60\%)\\ 4\;for\;fourth\;quittile\;(60-80\%)\\ 5\;for\;fifth\;quittile\;(80-100\%)\\ \end{array} \right.\]  
Once the two scores have been calculated, the client's cluster was evaluated using the segmentation map (Figure 5). The segment is given by the Cartesian point (\(R\), \(F\)) in the graph. Furthermore, various optimization techniques of the predictive algorithm were elaborated, such as the Grid search technique and the Feature Selection. Grid search, also called parameter sweep, is useful for finding the best combination of hyperparameters for the algorithm, which specifically are: max_depth, min_child_weight, learning_rate (eta), n_estimators, subsample, colsample_bytree, reg_lambda, and reg_alpha  
Figure 5: Segmentation map of customer clustering. in order to minimize the cost function as much as possible. The most-used error estimation parameters are: root mean square error (RMSE), mean square error (MSE), mean absolute error (MAE), mean square error on prediction (RMSEP), cross correlation coefficient (R), and standard deviation (SD) [46; 47; 48; 49]. The reliability of the algorithms depends on the estimates of the errors that are made during data processing. The errors may also depend on the creation of inefficient training models. The cost function chosen to evaluate the accuracy of the implemented algorithm was RMSE. The other technique used to increase the accuracy of the algorithm was the Feature Selection, which consists in the selection of the features with the highest relevance for the provided training set. In fact, there is no unique set of features suitable for predicting the quantities that are sold of all products. The paper concludes with a detailed paragraph on the testing phase of the algorithm and the results obtained. We used the Python programming language to implement the XGboost algorithm. In particular, Python provides the XGBoost and scikit-learn open-source libraries. Using Scikit-learn Wrapper interface [50; 51; 52] for implementing XGBoost provides the opportunity to run the algorithm with the maximum number of parallel threads via the optional n_ jobs parameter. The n_ jobs = \(-1\) option, permitting one to use all CPU cores, saves time, especially for trees that use a large number of nodes. Parallel computing is widely used in various sectors [53; 54; 12; 55] because it optimizes computational costs.