Bag2image: a multi-instance network traffic representation for network security event prediction

Jiachen Zhang, Daoqi Han, Zhaoxuan Lv, Yueming Lu, Junchao Duan, Yang Liu, Xinyu Zhang

Abstract

In practical scenarios, security events triggered by abnormal network traffic often result from the collective behavior of multiple data streams, embodying group security events with collective characteristics. Existing research methods, focusing on individual data streams, lack a macroscopic analysis and struggle with challenges of analyzing massive, imbalanced data sets. To address these challenges, this paper adopts a multi-instance learning (MIL) approach, mapping multiple data streams into a "bag" with a coarse-grained approach, where each bag corresponds to a security event label and each data stream represents an instance. We propose a multi-instance network traffic conversion method, Bag2Image, which transforms temporal multi-instance network traffic data into image representations, preserving the spatio-temporal characteristics of instances within the bag through image channels and pixels. This strategy allows the network security event prediction task to be approached as an image classification problem, leveraging advanced image classification techniques for prediction. Our experiments demonstrate superior performance on both the UNSW-NB15 dataset and a private dataset, achieving F1 scores of 77.9% and 74.4%, respectively.

Introduction

Predicting network security events is a critical challenge in cybersecurity. Traditional machine learning approaches typically analyze individual data streams (single-instance learning). However, modern cyber-attacks, such as Distributed Denial of Service (DDoS), are inherently collective behaviors. Analyzing a single stream in isolation often misses the macroscopic patterns necessary for accurate prediction. Furthermore, fine-grained labeling of individual packets is labor-intensive and often impractical in real-world environments characterized by massive data volumes and significant class imbalance.

This research introduces Bag2Image, a framework that reframes network security event prediction as a Multi-Instance Learning (MIL) problem. By grouping network flows into time-based "bags," the method captures the collective dynamics of network traffic while simplifying the labeling process.

The Bag2Image Framework

The core of the Bag2Image method lies in its ability to convert raw, temporal network logs into a visual format that can be processed by state-of-the-art computer vision models.

1. Multi-Instance Representation and Time-Slicing

The process begins by segmenting network traffic into discrete time windows. A large time window (the "bag") is further divided into smaller sub-windows ("sub-bags"). Statistical features such as mean, median, and sum are extracted from the flows within these sub-bags to create a standardized feature matrix. This approach handles the variable length of network traffic data and prepares it for transformation.

Schematic of detection and prediction time windows showing how input vectors are mapped to event labels over time.

2. Bag-to-Image via Gramian Angular Fields (GAF)

The innovation of Bag2Image is the use of Gramian Angular Fields (GAF) to encode 1D time-series data into 2D images. GAF translates temporal data into polar coordinates, preserving the temporal relationships and relative changes within the network traffic. By using two variants—Gramian Angular Summation Fields (GASF) and Gramian Angular Difference Fields (GADF)—the framework generates multi-channel images where pixels represent spatio-temporal traffic features.

Experimental Results

The authors evaluated the Bag2Image method using the public UNSW-NB15 dataset and a Private Dataset containing 10 million real-world flow records. The performance was compared against six baseline MIL algorithms and various classification models, including ResNet18 and ResNet50.

  • UNSW-NB15: The MI-GADF method paired with ResNet50 achieved an F1-score of 77.9%, a 4.1% improvement over the second-best baseline.
  • Private Dataset: The model achieved an F1-score of 74.4%, representing a 13.5% improvement over the runner-up.

The results indicate that deep learning models (CNNs) significantly outperform traditional machine learning models like XGBoost or Random Forest when utilizing the Bag2Image representation. Notably, the recall rates also saw substantial increases (4.1% and 13.2% respectively), reducing the number of missed security events.

Conclusion and Future Work

Bag2Image demonstrates that transforming network traffic into images allows cybersecurity tasks to benefit from the rapid advancements in computer vision. By utilizing weak supervision through MIL, the framework makes real-world deployment more feasible.

Future research will focus on addressing adversarial vulnerabilities, where attackers might attempt to manipulate traffic to evade detection. Additionally, implementing incremental learning strategies will be essential to handle "concept drift" as new attack patterns emerge, ensuring the model remains effective over time without losing knowledge of historical threats.

Summary updated

BibTeX
@inproceedings{zhang2025bag,
  author = {Jiachen Zhang and Daoqi Han and Zhaoxuan Lv and Yueming Lu and Junchao Duan and Yang Liu and Xinyu Zhang},
  title = {{Bag2image: a multi-instance network traffic representation for network security event prediction}},
  booktitle = {Cybersecurity},
  year = {2025},
  doi = {10.1186/s42400-024-00292-y},
}
Figure