# Intrusion Detection Model Based on Improved Transformer
## 4 Results
### Experimental Results and Discussion
#### 4.3.3 Comparison Experiments of Different Sampling Methods  
To address the issues of imbalanced dataset and class overlapping, a hybrid sampling method (KNN-based under-sampling and Borderline-SMOTE over-sampling techniques) was used in this paper to handle the dataset. To verify the effectiveness of the proposed method, two comparative experiments were set up in this section using different sampling methods:  
1. Under the same experimental conditions, five different single sampling methods were used to handle imbalanced datasets: random over-sampling, SMOTE, Borderline-SMOTE, random under-sampling, and KNN-based under-sampling. Finally, binary and multi-class experiments were conducted using the proposed model, and the results are shown in Table 2 to verify the effectiveness of the proposed method.
2. Under the same experimental conditions, the above five sampling methods were randomly combined using a mixed sampling approach to handle imbalanced datasets. Finally, binary and multi-class classification experiments were performed using the proposed model, and the results are shown in Table 3.  
\begin{table}
\begin{tabular}{c c c c c} \hline \hline \multirow{2}{*}{**Sampling Method**} & \multicolumn{2}{c}{**Binary Classification**} & \multicolumn{2}{c}{**Multi-Classification**} \\ \cline{2-5}  & **Accuracy** & **F1-Score** & **Accuracy** & **F1-Score** \\ \hline Random over-sampling & 0.819 & 0.813 & 0.809 & 0.805 \\ SMOTE & 0.833 & 0.827 & 0.816 & 0.813 \\ Borderline-SMOTE & 0.845 & 0.841 & 0.824 & 0.818 \\ Random under-sampling & 0.811 & 0.807 & 0.807 & 0.803 \\ KNN-based under-sampling & 0.830 & 0.825 & 0.819 & 0.814 \\ \hline \hline \end{tabular}
\end{table}
Table 2: Comparison experiments of different individual sampling methods.  
Figure 8: The impact of different degrees of dimensionality reduction on the model accuracy.  
According to Table 2, Borderline-SMOTE achieved an accuracy of 84.5% and an _F1-score_ of 84.1% in binary classification. In comparison to random over-sampling and SMOTE, Borderline-SMOTE improved the accuracy by 2.6% and 1.2%, respectively. In multi-class classification, Borderline-SMOTE achieved an accuracy of 82.4% and an _F1-score_ of 81.8%. Borderline-SMOTE improved the accuracy by 1.6% and 0.8% in comparison to random over-sampling and SMOTE, respectively. In the case of under-sampling methods, KNN-based under-sampling achieved an accuracy of 83% and an _F1-score_ of 82.5% in binary classification. KNN-based under-sampling improved the accuracy by 2.6% compared to random under-sampling. In multi-class classification, KNN-based under-sampling achieved an accuracy of 81.9% and an _F1-score_ of 81.4%, with an accuracy improvement of 1.2% in comparison to random under-sampling. Analysis of the reasons for this shows that in over-sampling methods, random over-sampling and SMOTE randomly sample the data points, while Borderline-SMOTE over-samples only the Danger class samples. This approach balances the dataset while also alleviating the class overlap problem, thereby enhancing the separability of the data and improving the model's performance. Similarly, in under-sampling methods, KNN-based under-sampling selectively removes overlapping samples that are prone to cause misclassification by the model. This approach balances the dataset while also alleviating the class overlap problem, thereby enhancing the separability of the data and improving the model's performance.  
According to Table 3, the proposed hybrid sampling algorithm (KNN-based under-sampling and Borderline-SMOTE over-sampling techniques) outperformed other combinations of hybrid sampling algorithms with the highest accuracy and _F1-score_ on both binary and multi-class classification tasks. Analysis indicates that the combination of these two techniques not only balances the dataset in terms of quantity but also maximally mitigates class overlap by complementing each other's effects on overlapping samples, improving the separability of the dataset and thus enhancing the model's detection ability.