Abstract
In recent years, there has been a growing interest in using Machine Learning (ML), especially Deep Learning (DL) to solve Network Intrusion Detection (NID) problems. However, the feature distribution shift problem remains a difficulty, because the change in features' distributions over time negatively impacts the model's performance. As one promising solution, model pretraining has emerged as a novel training paradigm, which brings robustness against feature distribution shift and has proven to be successful in Computer Vision (CV) and Natural Language Processing (NLP). To verify whether this paradigm is beneficial for NID problem, we propose SwapCon, a ML model in the context of NID, which compresses shift-invariant feature information during the pretraining stage and refines during the finetuning stage. We exemplify the evidence of feature distribution shift using the Kyoto2006+ dataset. We demonstrate how pretraining a model with the proper size can increase robustness against feature distribution shifts by over 8%. Moreover, we show how an adequate numerical embedding strategy also enhances the performance of pretrained models. Further experiments show that the proposed SwapCon model also outperforms eXtreme Gradient Boosting (XGBoost) and K-Nearest Neighbor (KNN) based models by a large margin.
Introduction: The Challenge of Temporal Decay
Machine Learning (ML) is highly effective at identifying malicious network traffic, but it struggles with "temporal decay." A model trained on network data from one year might perform poorly in subsequent years because software updates, new user behaviors, and hardware changes alter the underlying distribution of the data—a phenomenon known as feature distribution shift.
Most existing NID research assumes that training and testing data come from the same distribution (IID). In the real world, this is rarely true. Constant retraining and manual labeling are expensive and often impractical. This research seeks to build models that are inherently robust to these shifts without requiring constant human intervention.
Methodology: The SwapCon Framework
The proposed SwapCon framework leverages a two-stage training paradigm designed to learn time-invariant features:
- Contrastive Pretraining: The model is first trained in a self-supervised manner. It uses a "swapping" augmentation strategy where the order of features in a sample is randomized. The model uses Noise Contrastive Estimation (NCE) loss to learn a latent space where a sample and its "swapped" version are close together, while different samples are pushed apart.
- Finetuning: The pretrained model is then fine-tuned on labeled data for the specific task of binary classification (Benign vs. Malicious).
A critical component of this method is Numerical Feature Embedding. Instead of feeding raw numbers into the neural network, three strategies were tested: Exponential Binning (EB), Piecewise Linear Embedding (PLE), and Learnable Embedding (LE). PLE proved most effective by expanding the feature space while preserving inherent relationships between values.
Experimental Setup
The study utilizes the Kyoto2006+ dataset, containing 10 years of real-world network traffic (2006–2015). To test for distribution shift, data is split into:
- IID: Testing data from the same time period as training.
- NEAR: Testing data from years immediately following the training period.
- FAR: Testing data from several years after the training period (extreme shift).
Key Results and Insights
- Superiority over Baselines: On the most challenging "FAR" split, SwapCon achieved an AUC of 72.93%, whereas XGBoost plummeted to 47.31% and KNN fell to 32.36%. This suggests that traditional models essentially "break" when the data distribution shifts significantly over years.
- Robustness Gain: Pretraining with the correct model size and embedding strategy increased robustness against distribution shifts by over 8% compared to non-pretrained versions.
- The Complexity Paradox: For "FAR" data, simpler models or fixed weights often performed better. Complex models that are fully fine-tuned tend to "forget" general patterns learned during pretraining and overfit to the training set's specific distribution.
Conclusion
SwapCon demonstrates that contrastive pretraining can significantly mitigate the impact of feature distribution shift in NID. While model size sensitivity and embedding bias remain areas for future research, the framework provides a more stable and robust alternative to traditional ML models for long-term network security monitoring.
Summary updated