# Trustworthy AI and Federated Learning for Intrusion Detection in 6G-Connected Smart Buildings
## 7 Trustworthy AI Solution for Intrusion Detection in Smart Buildings
### Centralized ML Benchmarks  
Before implementing the FL setting, the data cleaning and pre-processing system, along with the CNNs, was tested in a centralized environment to establish a performance benchmark. This benchmark was used to evaluate the impact of decentralization on performance and results. The sensor and network data were partitioned into training, test, and validation sets using a 70-20-10 stratified split, ensuring the distribution of labels was preserved across the splits. After training the network and sensor CNNs for 300 and 200 epochs, respectively, until the validation loss began to increase, confusion matrices were computed using the validation set. The following explains the key elements of the confusion matrices:  
* **True Positives (TP):** Correctly identified positive instances;
* **True Negatives (TN):** Correctly identified negative instances;
* **False Positives (FP):** Negative instances incorrectly identified as positive;
* **False Negatives (FN):** Positive instances incorrectly identified as negative. Using these matrix elements, the following metrics were computed:  
Figure 10: Sample input IoT image. * **Accuracy**: The proportion of the total number of correct predictions that were correct, calculated as follows: \[\text{Accuracy}=\frac{\text{TP}+\text{TN}}{\text{TP}+\text{TN}+\text{FP}+\text{ FN}};\]
* **Precision (Positive Predictive Value)**: The proportion of positive cases that were correctly identified, calculated as follows: \[\text{Precision}=\frac{\text{TP}}{\text{TP}+\text{FP}};\]
* **Recall (Sensitivity)**: The proportion of correctly identified actually positive cases, calculated as follows: \[\text{Recall}=\frac{\text{TP}}{\text{TP}+\text{FN}};\]
* **F1 Score**: The harmonic mean of precision and recall, calculated as follows: \[\text{F1}=\frac{2\times\text{Precision}\times\text{Recall}}{\text{Precision}+ \text{Recall}};\]
* **FPR (False-Positive Rate)**: The proportion of actual negative cases incorrectly identified as positive, calculated as follows: \[\text{FPR}=\frac{\text{FP}}{\text{FP}+\text{TN}};\]
* **FNR (False-Negative Rate)**: The proportion of actual positive cases incorrectly identified as negative, calculated as follows: \[\text{FNR}=\frac{\text{FN}}{\text{FN}+\text{TP}}.\]  
To calculate these metrics for the multi-class classification problem, which has eight classes for network data and three classes for sensor data, the matrix values are considered as follows:  
* The network confusion matrix considers a value of 5 to be indicative of a negative outcome, representing the \"normal\" class. Conversely, all other classes, which represent attacks, are regarded as positive. * The confusion matrix employed by the sensor exclusively considers class \"1\" as positive and class \"0\" as negative samples, given that the class \"2\", which represents a sensor that is off, was removed. The network confusion matrix is represented in Figure 11, while the sensor confusion matrices are represented in Figure 12. The metrics extracted from the matrices are reported in Table 8. The CNN network's performance metrics demonstrate excellent results across all evaluation criteria, with an accuracy of 99.23%. This suggests that the model is capable of making accurate predictions in the majority of cases. Moreover, the precision of 99.28% and the recall of 99.84% demonstrate the high capacity of the model in correctly identifying positive cases while minimizing false positives and negatives. The network demonstrates robust capability in distinguishing between positive and negative cases, with a false-positive rate of 4.76% and a low false-negative rate of 0.16%. However, the performance of the sensor CNN exhibits considerable variability. Some sensors, such as GPS, motion light, and garage door sensors, achieve perfect scores across all metrics, while others, like refrigerator and weather sensors, exhibit high false-positive rates, despite having perfect recall.