# Blockchain-Driven Intelligent Scheme for IoT-Based Public Safety System beyond 5G Networks
## 3 Role of Blockchain in 6G Services
### Intelligence Layer
#### 4.2.2 ML Classification Approach  
The CSV file has missing values, noise, and unmanaged data columns that affect the performance of the ML classifier. To overcome this issue, we replace the missing value with central tendency, i.e., mean value. Further, the dataset has numeric and textual values (alphanumeric), such as location, crime, and weapon types; therefore, there is a need to convert nonnumerical data into numeric data. We apply the label-encoding technique \(\mathbf{L}_{e}\) that assigns a numerical value to each categorical value.  
\[\forall b_{3},b_{4},b_{5}\xrightarrow{\text{apply}}\mathbf{L}_{e}\in\Psi \tag{3}\]  
After reading the CSV file, we realize that the dataset attributes have different datatype \(D\), such as an object, int, and float. However, certain ML classifiers do not recognize attributes with object datatype. To overcome this issue, we change the datatype from floating to the int using the \(astype()\) function.  
\[\forall b_{7},b_{8}\xrightarrow{\text{change}}D \tag{4}\]Then, we analyze outliers that corrupt the dataset and mislead the ML classifiers for the wrong classification. For that, we apply outlier detection techniques that normalize the data using a standard scale without distorting differences in the ranges of values or losing information. Various normalization approaches exist, such as min-max, standardization scaling, and Z-score. Here, we apply the min-max method that is mathematically represented as follows.  
\[\phi^{{}^{\prime}}=\frac{\vartheta-\vartheta_{min}}{\vartheta_{max}-\vartheta_{ min}} \tag{5}\]  
This normalization technique obtains all the scaled data into the range of 0 to 1. After preprocessing the data, we split the data into two classes, training and testing, where we train 80% of the data and validate 20% of the data. We pass the training dataset (\(\Psi_{T1}\)) into the ML classifier that classifies the data into attack (1) and nonattack (0) categories.  
\[\Psi_{T1}\xrightarrow{fed}\mathbf{ML}_{c}\xrightarrow{classify}data\begin{cases} 0\\ 1\end{cases} \tag{6}\]  
After training the model, we feed the testing dataset (\(\Psi_{T2}\)) into the ML classifier that validates the results based on the \(\Psi_{T1}\).  
\[\Psi_{T2}\xrightarrow{fed}\mathbf{ML}_{c}\xrightarrow{classify}data\begin{cases} 0\\ 1\end{cases} \tag{7}\]  
Here, we applied different ML classifiers, such as XGBoost, random forest (RF), k-nearest neighbor (KNN), logistic regression (LR), and support vector machine (SVM), that classify the data into attack and nonattack. Among all these classifiers, we obtained the best results in terms of the accuracy and log loss score from the XGBoost algorithm. The XGBoost classifier gives effective results with the larger dataset. In this classifier, the data are considered for each tree, and we can increase the depth of the tree and decrease the _min_child_weight_ that handles the overfitting issue in the dataset. The classified data are susceptible, which raises the security issue in a public safety application. To overcome this issue, we utilize the IPFS-based blockchain network that offers the data's authentication and confidentiality, preventing fraud on the dataset.