# Prediction of Residual Stress of Carburized Steel Based on Machine Learning
## 4 Results and Discussion
### Prediction Results and Analysis of Residual Stress
#### 4.3.2 Prediction of Residual Stress Based on the SVM Model  
First, the data were preprocessed and normalized to eliminate dimensional differences between the parameter ranges and improve the accuracy of the SVM model:  
\[Z=\frac{X-\mu}{\sigma} \tag{1}\]  
where \(Z\) denotes the normalized data, \(X\) is the original data from the datasets, and \(\mu\) and \(\sigma\) represent the mean and standard deviation of the original data, respectively. The use of kernel functions to embed samples into the high-dimensional feature space is crucial to constructing a generalizable SVM model. This paper adopted a radial basis function (RBF) kernel suitable for nonlinear problems. The generalizability of the SVM based on RBF is controlled by a key parameter, namely C [37], which is the penalty parameter in the SVM objective function and is set to a constant greater than zero. Setting parameter C to a too-large value leads to overfitting, while setting C to a too-small value leads to underfitting. The search process to find the optimal parameters was conducted for 500 generations, and the search range for the parameter C was 0-500. The dataset obtained in the experiment contained a total of only 1200 samples. Because the number of samples in the current work was quite limited, the performance of the trained model varied substantially based on the division of the training and test sets. In addition, a random division of the dataset can easily lead to unbalanced data distributions and inaccurate model performance evaluations. Therefore, this study used 10-fold cross-validation to evaluate model generalizability. We adopted \(R\)-squared (\(R^{2}\)) and mean absolute error (_MAE_) as the evaluation indicators:  
\[R^{2}=1-\frac{\sum_{i=1}^{m}\left(y_{i}-\hat{y_{i}}\right)^{2}}{\sum_{i=1}^{m} \left(y_{i}-\overline{y_{i}}\right)^{2}} \tag{2}\] \begin{table}
\begin{tabular}{c c c c c c} \hline \multirow{2}{*}{**Depth (um)**} & \multirow{2}{*}{**C (\%)**} & **Acicular** & **Retained** & **Lath** & **Residual** \\  & & **Martensite (\%)** & **Austenite (\%)** & **Martensite (\%)** & **Stress (MPa)** \\ \hline
98 & 0.60 & 0.78 & 0.22 & 0 & \(-\)334 \\ \hline
232 & 0.56 & 0.79 & 0.21 & 0 & \(-\)377 \\ \hline
305 & 0.53 & 0.80 & 0.20 & 0 & \(-\)343 \\ \hline
456 & 0.48 & 0.76 & 0.19 & 0.05 & \(-\)242 \\ \hline
538 & 0.46 & 0.69 & 0.18 & 0.13 & \(-\)210 \\ \hline
610 & 0.43 & 0.62 & 0.17 & 0.21 & \(-\)185 \\ \hline
687 & 0.40 & 0.54 & 0.17 & 0.29 & \(-\)161 \\ \hline
759 & 0.37 & 0.50 & 0.16 & 0.34 & \(-\)155 \\ \hline
887 & 0.31 & 0.38 & 0.14 & 0.48 & \(-\)125 \\ \hline
985 & 0.27 & 0.28 & 0.11 & 0.61 & \(-\)77 \\ \hline
1089 & 0.23 & 0.15 & 0.06 & 0.79 & \(-\)69 \\ \hline \end{tabular}
\end{table} 
Table 4: 23 CrNi3 Mo carburized steel Process 1 data. \[MAE=\frac{1}{m}{\sum_{i=1}^{m}}\big{[}y_{i}-\hat{y}_{i}\big{]} \tag{3}\]  
where \(m\) is the number of samples, \(y_{i}\) is the true value, \(\hat{y}_{i}\) is the predicted value, \(\overline{y}_{i}\) is the average of the real labels of m samples, and \(i\) is the sample label. To further verify the model prediction effect, we introduced a decision tree model to predict the residual stress. First, the hyperparameters of the model were optimized; then, the same 5-fold cross-validation approach was used to compare the measured and predicted residual stress values in the test dataset with the fitted straight line shown in Figure 9.  
Figure 9 shows the 5-fold cross-validation results for the SVM and decision tree (DT) models. Most of the points in the test dataset lie either on or very close to the straight line with a slope of 1, which strongly indicates that most of the predicted values are in good agreement with the experimental values. This finding demonstrates that both the SVM and DT models have good generalizability and achieve high prediction accuracy. Figure 9 shows that the values of SVM and DT model R\({}^{2}\) are 0.975 and 0.953, respectively, and their MAE values are 7.52 MPa and 12.45 MPa, respectively.