# Prediction of Cotton Yarn Quality Based on Attention-GRU
## 3 Case Analysis
### Model Testing and Comparison  
Firstly, the training of the four models was conducted using the provided dataset, resulting in the derivation of iterative loss values and training durations for each model. The training performance parameters of each model can be inferred from Figure 7 and Table 3. It is observed that the BP neural network exhibits the fastest training speed; however, its loss consistently remains at a higher level and cannot be reduced. In contrast, the GRU model demonstrates a 14.3% reduction in training duration compared to LSTM. Furthermore, the attention-GRU predictive model, which has undergone optimization through attention mechanisms to enhance input parameter quality, achieves the lowest average training loss of 0.005. From the point of view of actual yarn production cycle and cost of spinning mill, although the attention-GRU model after adding attention mechanism will increase a certain second time cost in training time compared with ordinary GRU, in fact, textile enterprises can accept the time cost of this second level. On the contrary, if the quality of the yarn is not guaranteed, the impact on production is huge. Because the production cycle of yarn is long, once the yarn quality problem occurs, it can only be found at the end of the yarn production process, which greatly extends the reaction adjustment time of the corresponding process and cannot be dealt with in time so that a large number of yarn quality is not up to standard, resulting in production waste, which is unacceptable to textile enterprises. Thus, despite the extension of training duration due to the attention  
\begin{table}
\begin{tabular}{c c c c c c c c c c c c c c} \hline \hline \multirow{2}{*}{ \begin{tabular}{c} **Micronaire** \\ **Value** \\ \end{tabular}  } & **Fiber** & **Fiber** & **Short** & **Criding** & **Carding** & **Feed** & **Draft-** & **Rough** & **Rough** & **Fine** & **Fine** & **Yarn** & **Yarn** \\  & **Fine-** & **Matu-** & **Fiber** & **Ney** & **Cylin-** & **Doffer** & **Roller** & **ing** & **Yarist** & **Spin-** & **Twist** & **Spin-** \\  & **Strength** & **ness** & **rity** & **Rate(\%)  
mechanism within the attention-GRU model, it ultimately attains the lowest loss value among the four models. This highlights the efficacy of this mechanism in enhancing the model's ability to discern complex patterns within the dataset, thereby substantiating its effectiveness in predicting the quality of regular carded yarn. With the objective of maintaining the superior predictive accuracy of the attention-GRU model proposed in this paper while further reducing the number of model iterations and training time and enhancing predictive efficiency, a strategy involving the implementation of an adaptive loss change threshold was employed for model retraining, as illustrated in Figure 8. Taking the total iteration count from the model parameter settings table in Section 3.2 as a reference, corresponding positive loss change values were calculated for the first three-quarters of the total iteration count. This calculation yielded an adaptive loss change threshold of 0.00074 for the current training dataset. Ultimately, the optimal iteration count for the model was determined as 7535 iterations, corresponding to a loss value of 0.0048 (point 'e'). Following model optimization, the training duration was reduced to 24.35 s. \begin{table}
\begin{tabular}{c c c c c} \hline \hline
**Method** & **BP** & **LSTM** & **GRU** & **AT-GRU** \\ \hline Training Duration (s) & 10.32 & 27.84 & 21.27 & 32.31 \\ Average Loss Value & 0.019 & 0.009 & 0.008 & 0.005 \\ \hline \hline \end{tabular}
\end{table} 
Table 3: Training duration and average loss value of each model. Figure 7: Iteration loss of each prediction model. After the training process, a correlation analysis was conducted on the final data of the four models. To assess the degree of proximity between the actual quality data and the predicted values of the models, the coefficient of determination \(R^{2}\) was introduced.