## 3 Machining Quality Prediction Method Based on XGBoost Hyperparameter Optimization
### XGBoost Algorithm
\begin{array}{l}F_{obj}^{(k)}=\sum\biggl{[}L(y_{i},\hat{y}_{i}^{(k-1)})+ \partial_{\hat{y}_{i}^{(k-1)}}L(y_{i},\hat{y}_{i}^{(k-1)})\cdot f_{k}(x_{i})+ \frac{1}{2}\partial_{\hat{y}_{i}^{(k-1)}}^{2}L(y_{i},\hat{y}_{i}^{(k-1)})\cdot f _{k}^{2}(x_{i})+\Omega(f_{k})\biggr{]}+C_{1}\end{array}  \tag{7}\]  
where \(\partial_{\hat{y}_{i}^{(k-1)}}L(y_{i},\hat{y}_{i}^{(k-1)})\) and \(\partial_{\hat{y}_{i}^{(k-1)}}^{2}L(y_{i},\hat{y}_{i}^{(k-1)})\) represent the first and second derivatives of the loss function with respect to the model, respectively. Let \(g_{i}=\frac{\partial L(y_{i},\hat{y}^{(k-1)})}{\partial\hat{y}^{(k-1)}}\) and \(h_{i}=\frac{\partial^{2}L(y_{i},\hat{y}^{(k-1)})}{\partial\hat{y}^{(k-1)}}\) be substituted into Formula (7), where \(L(y_{i},\hat{y}_{i}^{(k-1)})\) is a constant, and the constant has no effect on the solution of the objective function. Therefore, Formula (7) can be rewritten as follows:  
\[ \begin{array}{l}F_{obj}^{(k)}=\sum\limits_{i=1}^{n}\biggl{[}g_{i}f_{k}(x_{ i})+\frac{1}{2}h_{i}f_{k}^{2}(x_{i})\biggr{]}+\Omega(f_{k})\end{array}  \tag{8}\]  
Bringing Formula (5) into Formula (8) can obtain the following:  
\[ \begin{array}{l}F_{obj}^{(k)}=\sum\limits_{i=1}^{n}\biggl{[}g_{i}f_{k}(x_{ i})+\frac{1}{2}h_{i}f_{k}^{2}(x_{i})\biggr{]}+\gamma T+\frac{1}{2}\lambda\parallel \omega\parallel^{2}\\ =\sum\limits_{i=1}^{n}\biggl{[}g_{i}f_{k}(x_{i})+\frac{1}{2}h_{i}f_{k}^{2}(x_{ i})\biggr{]}+\gamma T+\frac{1}{2}\lambda\sum\limits_{i=1}^{T}\omega_{i}^{2} \end{array}  \tag{9}\]  
For a regression tree model, each input sample is assigned to a specific leaf node of the tree, where it is associated with a weight value \(\omega\) of that leaf node. Consequently, the regression tree model \(f_{k}(x_{i})\) can be represented by the weight value \(\omega_{j}\) of the corresponding leaf node \(j\). The sample set assigned to leaf node \(j\) is defined as \(I_{j}\), which satisfies Formula (10). \[I_{j}=\{i|f_{k}(x_{i})=j\} \tag{10}\]  
Bringing \(\omega_{j}\) and (10) into Formula (9), we can obtain the following:  
\[ \begin{array}{l}F_{obj}^{(k)}=\sum\limits_{j=1}^{T}\left[\left(\sum\limits_{ i\in I_{j}}g_{i}\right)\omega_{j}+\frac{1}{2}\left(\sum\limits_{i\in I_{j}}h_{i}+ \lambda\right)\omega_{j}^{2}\right]+\gamma T\end{array}  \tag{11}\]  
Formula (11) can be regarded as a quadratic function with \(\omega_{j}\) as the independent variable, assuming that the quadratic function has a minimum value when \(\omega_{j}=\omega_{j}^{*}\). For the convenience of solving \(\omega_{j}^{*}\), let \(G_{j}=\sum_{i\in I_{j}}g_{i}\) and \(H_{j}=\sum_{i\in I_{j}}h_{i}\). Bring \(G_{j}\) and \(H_{j}\) into the following Formula (11):  
\[F_{obj}^{(k)}=\sum_{j=1}^{T}\biggl{[}\bigl{(}G_{j}\bigr{)}\omega_{j}+\frac{1}{2} \bigl{(}H_{j}+\lambda\bigr{)}\omega_{j}^{2}\biggr{]}+\gamma T \tag{12}\]  
According to the formula of the most value of the quadratic function, \(\omega_{j}^{*}\) can be obtained. \[\omega_{j}^{*}=\frac{G_{j}}{-2\times\frac{1}{2}\bigl{(}H_{j}+\lambda\bigr{)}}= -\frac{G_{j}}{H_{j}+\lambda} \tag{13}\]  
The minimum of the objective function \(F_{obj}^{(k)}\) is as follows:  
\[F_{obj}^{(k)}=-\frac{1}{2}\sum_{j=1}^{T}\frac{G_{j}^{2}}{H_{j}+\lambda}+\gamma T \tag{14}\]  
Equation (14) can be used to evaluate the performance of the regression tree model. A smaller value of \(F_{obj}^{(k)}\) indicates better performance of the model. During the training process, Equation (14) is used to assess various regression tree models, allowing for the selection of the optimal model.