# Poisoning Attacks against Communication and Computing Task Classification and Detection Techniques
## 4 The Proposed 2C Task Classification Technique  
The stochastic nature of the 5G and 6G usage patterns and the unavailable knowledge about the network nodes make classification optimization of the requests challenging. To address this, the focus was on self-learning networks and systems that could autonomously manage resources and control functions.  
The method of _k-means_ clustering is a simple, iterative unsupervised technique used to partition the dataset into distinct groups of 2C requests or clusters. Each request belongs to the cluster with the closest mean (cluster centers or cluster centroids). This algorithm aims to minimize the within-cluster variance and maximize the between-cluster variance.  
Our _k_-means algorithm starts by randomly initializing \(k\) cluster centroids within the 3D feature space. Then, it assigns each data point to the nearest centroid based on a distance metric, which is the 3D Euclidean distance here. After that, it recalculates the centroids of each cluster by taking the mean of all data points assigned to that cluster. It repeats the assignment step, assigning each data point to the nearest centroid based on the updated centroids. It continues the update and reassignment steps iteratively until convergence is reached.  
Convergence is achieved when the centroids no longer move significantly or when a predefined maximum number of iterations is reached. The algorithm converges to a solution where each data point belongs to the cluster with the closest centroid. The _k-means_ algorithm seeks to minimize the within-cluster sum of squared distances (inertia) through iterative optimization of the cluster assignments and updating the cluster centroids. It is important to note that the _k-means_ algorithm is sensitive to the initial random initialization, and the algorithm may converge to different solutions depending on the starting points.  
However, due to the large number of operations performed by the _k-means_ algorithm, it is not convenient to repeat the calculations for the arrival of a limited number of tasks. To handle this, a simple algorithm with lower complexity and a training-free process is used. Here, we suggest the use of the _k' nearest neighbors_ algorithm (_k'-NN_), where _k'_ is a different value from \(k\). It focuses on the similarity between the input data and the labeled examples in the dataset.  
The assembled algorithm collects a labeled dataset consisting of the input samples (2C requests clustered by _k-means_) and their corresponding class labels (centroids obtained by _k-means_). Then, it receives an unlabeled data point (new incoming 2C tasks) that needs to be classified or predicted. After that, the similarity (distance) between the new request points and all the labeled requests in the dataset is computed. The used distance metric is the same as the one used in _k-means_) (i.e., the 3D Euclidean distance).  
The next step of the algorithm is voting; in other words, _k'-NN_ selects the _k'_ nearest neighbors to the input data point based on the calculated similarity, and then it determines the class label of the input data point by majority voting among the class labels of the _k'_ nearest neighbors. The algorithm returns the predicted class label or the target value for the new data point.  
Assembling both techniques leads to a hybrid _k-means_/_k'-NN_ technique described by the flowchart in Figure 2. Where E is the list of all events (2C requests and their arrivals) and I is a sub-event list during a single epoch (round). Epsilon and max_iter are the thresholds and the maximum number of iterations for _k_means_, respectively, and T is the time of a single epoch.  
Figure 2: Hybrid _k-means_ and _k’-NN_ algorithm.