# Machine Learning Prediction of Turning Precision Using Optimized XGBoost Model
## 4 Experimental Results  
### Performances of Different ML Models  
As described in Section 3, the ML models were trained and tested using the leave-one-out cross-validation technique with nine data samples. For each testing process, the prediction performance of the model was evaluated using three different metrics: the root mean square error (RMSE), the mean absolute error (MAE), and the coefficient of determination (\(R^{2}\)). The RMSE computes the square root of the ratio of the square of the errors between the predicted values and the actual values over the number of data instances. The square relationship in the RMSE formula renders the metric sensitive to very large or very small errors. A larger RMSE indicates a poorer prediction performance, and vice versa. The mean absolute error (MAE) computes the sum of the absolute values of the differences between the actual values of the machining error and the predicted values. In other words, a smaller MAE indicates a better prediction accuracy, and vice versa. Finally, the coefficient of determination (\(R^{2}\) or the \(R^{2}\) score) is a statistical measure representing the proportion of variance in the dependent variable. In other words, it provides an indication of how well (or otherwise) the prediction model fits the actual data. The \(R^{2}\) score has a value in the interval of [0, 1], where a value closer to 1 indicates a better fit of the prediction model. The leave-one-out cross-validation process revealed that all of the trained single models (RF, XGBoost, and DT) had a poor prediction performance. However, among the three models, the best performance was obtained by the XGBoost model, with a RMSE of 0.007887, a MAE of 0.0067, and an \(R^{2}\) score of 0.554. Accordingly, the XGBoost model was selected for further improvement using the SMOGN over-sampling method and four optimization algorithms. Figure 15 shows the learning curves of the four optimizers. Note that in compiling the results, the RMSE values of the optimizers were taken as the fitness value, and once a better fitness value was found in the model optimization process, it was used in place of the best fitness value. In other words, a lower learning curve in Figure 15 indicates an improved optimization performance, and shows that the CPSO optimizer yields the best learning performance. Figure 14: Optimized model training flowchart. Figure 19: SMOGN-GA-XGB prediction results: (**a**) comparison of actual and predicted precision values, and (**b**) residual plot. Figure 20: SMOGN-GW-XGB prediction results: (**a**) comparison of actual and predicted precision values, and (**b**) residual plot. For ease of visualization and comparison, the prediction errors with a value greater than 0.008 in Figures 16-22 are shown in orange, while those with a value between 0.003 and 0.008 are shown in green, and those with a value less than 0.003 are shown in blue. Thus, the prediction accuracy of each model can be crudely evaluated by the number of points of each color in the respective plots. A more quantitative evaluation of the performance of each model can be obtained from the corresponding RMSE, MAE, and \(R^{2}\) values. Figure 23 compares the predicted machining errors of the seven models with the actual machining error for each of the nine runs in the Taguchi OA. Overall, the results show that the SMOGN-CPSO-XGB model and SMOGN-GWO-XGB model yield the best fits with the actual prediction error in each run. By contrast, the RF model yields the poorest fit with the experimental data. Table 4 lists the MAE, RMSE, and R\({}^{2}\) values of the seven models. In general, the results confirm the effectiveness of the SMOGN technique and optimization algorithms in improving the prediction performance, compared with that of the single models. Moreover, the results confirm that, among all of the models, the XGBoost model optimized with SMOGN and CPSO achieves the lowest MAE and RMSE values and the highest \(R^{2}\) score. The values of \(R^{2}\) for SMOGN-CPSO-XGB and SMOGN-GWO-XGB are 0.661 and 0.64, respectively.