# Assembly Quality Detection Based on Class-Imbalanced Semi-Supervised Learning
## 2 Class-Imbalanced Semi-Supervised Learning
### Class-Imbalanced Learning  
Imbalanced learning is a machine learning paradigm in which the classifier learns from dataset with a skewed class distribution. In this paper, we modify the training losses to further improve the robustness of the model to the imbalanced dataset. There are two main methods for solving class imbalance in supervised learning: loss re-weighting and mini-batch resampling [33; 34; 35]. These methods make the proportion of samples of different classes in the training loss closer to the test distribution to achieve a better trade-off between the accuracy of majority and minority classes. However, the model's scale is usually massive relative to the number of samples of the minority class, so there is the problem of over-fitting to the minority class. Label-distribution-aware margin loss (LDAM Loss) [28] regularizes different classes according to the number of samples: The regularization of the minority class should be stronger than that of the majority class to boost the generalization ability of the model to the minority class without sacrificing the fitting ability to the majority class. Figure 5 shows an example of binary classification, where \(\chi_{1}\) and \(\chi_{2}\) represent the margin of majority class and minority class, respectively. Class margin is the minimum distance from all samples of this class to the decision boundary. The minority class should have a more significant margin than the majority class. For the multi-classification problem, when the margin of class \(c\) is satisfied \(\chi_{c}\propto 1/N_{c}^{1/4}\), the minimum test error can be obtained, where \(N_{c}\) is the sample number of class \(c\). Figure 4: Certainty driven selection method: (**a**) uncertainty estimation; (**b**) predictions selection based on certainty. Therefore, Hinge loss is adopted to enforce the class margin. For the labeled sample \((x_{i},y_{i})\), hinge loss is  
\[L_{hinge}=\max(\max_{l\
eq y_{i}}\{z_{l}\}-z_{y_{i}}+\Delta_{y_{i}},0), \tag{8}\]  
where \(z_{l}\) is the \(l\)th output of \(\hat{y}_{i}^{s}\) predicted by the student model, \(\Delta_{y_{i}}\) is the margin of class \(y_{i}\), satisfying \(\Delta_{y_{i}}=A/N_{y_{i}}^{1/4}\), and \(A\) is a constant for margin tuning. Since the hinge loss is non-convex and non-continuous, it is hard to optimize. A smoother cross-entropy loss with enforced class margin is adopted  
\[L_{\text{LDAM}}(\hat{y}_{i}^{s},y_{i})=-\log\frac{e^{z_{y_{i}}-\Delta_{y_{i}}} }{e^{z_{y_{i}}-\Delta_{y_{i}}}+\sum\limits_{l\
eq y_{i}}e^{z_{l}}}, \tag{9}\]  
The class imbalance will bring more challenges to the semi-supervised learning algorithm because, based on the smooth hypothesis, the decision boundary is located in the low-density area of the data space [23]. However, in the case of the class-imbalanced dataset, the high-density area of the minority class is sparse relative to the majority class, which causes that the decision boundary enters the minority class region, making the model predict the minority class samples to be the majority class. Therefore, to prevent the decision boundary from being overly smooth and infiltrating into the minority class areas, when the prediction given by the teacher model is the majority class, the consistency constraints should be suppressed. For \(m\) samples \(x_{j}\) from the certainty-driven selection, the compression consistency loss is defined as  
\[ \begin{split} L_{CCL}(\hat{y}_{j}^{s},\hat{y}_{j}^{t})=g(N_{c}) \
orm{\hat{y}_{j}^{s}-\hat{y}_{j}^{t}}^{2}\\ \text{where }g(N_{c})=\delta^{1-\frac{N_{\text{min}}}{N_{c}}}\end{split}  \tag{10}\]  
\(\hat{c}\) represents the class predicted by the model, \(\delta\in(0,1]\) is the compression coefficient, and \(N_{\text{min}}\) is the sample number of the class with the least samples. When \(N_{\hat{c}}=N_{\text{min}}\), \(g(N_{\hat{c}})=1\), the compression consistency loss of samples predicted to be the smallest class is the same as the typical consistency regularization loss (CRL).