# A Robust Machine Learning Model for Detecting XSS Attacks on IoT over 5G Networks
## 3 Proposed Methodology
### Classification Methods  
In this study, we employ several machine learning classification methods to detect XSS attacks within IoT environments over 5G networks. Each classifier has distinct advantages that make it well-suited for specific data characteristics and analysis needs. By leveraging these diverse techniques, we aim to enhance the robustness and accuracy of our model. Below, we provide an overview of the classification algorithms used in this study, including Decision Tree, Random Forest, and Naive Bayes. Figure 5: The Selected Features by Filter Feature Selection—NF-ToN-IoT-v2 dataset. Figure 6: The Selected Features by Filter Feature Selection—Edge-IIoTset dataset. **Decision Tree**: The decision tree algorithm classifies data by sequentially asking questions based on feature values, effectively splitting the data into branches that lead to classification decisions [40]. This tree-like structure is particularly user-friendly, as each decision node represents a test on a specific feature, and each leaf node represents a class label. Decision trees are simple to visualize, making them highly interpretable and accessible for understanding model behavior. The decision-making process within the tree uses the Gini impurity criterion (Equation (3)), which evaluates the quality of a split by measuring how well the nodes separate the classes. The Gini impurity for a node \(t\) is calculated as follows:  
\[Gini(t)=1-\sum_{i=1}^{c}p_{i}^{2} \tag{3}\]  
where \(p_{i}\) is the proportion of samples that belong to class \(i\) in node \(t\). The algorithm for Decision Tree classification is outlined in Algorithm 2. **Random Forest (RF)**: Random Forest is an ensemble learning method that builds a multitude of decision trees during training and combines their predictions [41]. For classification tasks, Random Forest takes the mode of the class predictions from individual trees, enhancing stability and accuracy. By randomly sampling both data and features, Random Forest introduces diversity among trees, which helps reduce overfitting, especially on high-dimensional data. The aggregation of trees in the forest is expressed in Equation (4) [42]. \[f(x)=\frac{1}{T}\sum_{i=1}^{T}f_{i}(x) \tag{4}\]  
where \(f_{i}(x)\) represents the prediction from the \(i\)th tree, and \(T\) is the total number of trees. This robust combination allows Random Forest to perform effectively in complex datasets with mixed-type features. The complete workflow of the Random Forest classification process is presented in Algorithm 3. ```
Input: Training dataset \(D\) with features and labels Output: A decision tree model for classification Initialize tree structure Define a splitting criterion (e.g., Gini impurity, information gain) while tree nodes are not pure do ifall instances at node belong to the same class Mark node as a leaf with the class label else Calculate splitting criterion for each feature Choose feature with the best split Partition dataset \(D\) based on selected feature Create child nodes for each partition
``` Input: Training dataset \(D\) with features and labels Output: A decision tree model for classification Initialize tree structure Define a splitting criterion (  
```
Input: Training dataset \(D\), number of trees \(T\), subset size \(N\) Output: A forest of decision trees for classification
1 Initialize an empty forest \(F\)
2 for each tree \(t=1\) to \(T\)
3 Draw a random bootstrap sample \(D_{t}\) from \(D\)
4 Select a random subset of features \(F_{t}\)
5 Train a decision tree \(DT_{t}\) on \(D_{t}\) using only \(F_{t}\)
6 Add \(DT_{t}\) to the forest \(F\) return Majority vote or mean prediction across all trees in \(F\)
```  
**Algorithm 3**Random Forest Classification  
**Naive Bayes (NB)**: Naive Bayes is a probabilistic classifier based on [PERSON] theorem, which calculates the probability of a class based on prior knowledge of conditions related to that class [43; 44].