# An Ensemble-Based Machine Learning Approach for Cyber-Attacks Detection in Wireless Sensor Networks
## 4 Simulation Results
WSS, Bagging, Boosting, and Stacking achieved an accuracy of 99% for the Blackhole dataset. The best TDMA dataset results were from Boosting and Stacking, with an accuracy of approximately 100%, while the accuracy for Bagging and WSS was 99.92%. \begin{table}
\begin{tabular}{c c} \hline \hline
**Dataset** & **Removed Features** \\ \hline All\_Attacks Dataset & Data\_Sent\_To\_BS, dist\_CH\_To\_BS \\ \hline Grayhole Class Dataset & SCH\_S, JOIN\_R, DATA\_R \\ \hline Blackhole Class Dataset & Data\_Sent\_To\_BS, dist\_CH\_To\_BS \\ \hline   Flooding Class Dataset & JOIN\_R, SCH\_S, DATA\_R \\ \hline Scheduling Class Dataset & dist\_CH\_To\_BS, Data\_Sent\_To\_BS, ADV\_R, DATA\_R \\ \hline \hline \end{tabular}
\end{table} 
Table 4: The Results of Mutual Information. Figure 4: Feature selection results for the extracted balanced dataset. Figure 5: Results of WSS, Bagging, Boosting, and Stacking in terms of the evaluation metrics. WSS, Bagging, Stacking, and Boosting classifiers achieved approximately the same results regarding probability of detection (Figure 5B). Boosting was higher for the Blackhole dataset, at 99.69%, and Stacking was higher for the Grayhole dataset, at 99.08%. All models using the Flooding and TDMA datasets achieved the same results, 100%. Figure 5C displays the results for probability of false alarm. WSS achieved the best results for the All_attacks, Blackhole, Grayhole, Flooding, and TDMA datasets, at 1%, 1.23%, 1.54%, 0%, and 0.155%, respectively. Boosting achieved the same result as WSS for the Flooding Dataset, while Bagging achieved the same result as WSS for the TDMA dataset. WSS achieved the best results for probability of misdetection: 0.2% and 0.76% for the All_attack and Grayhole datasets (Figure 5D). Stacking and Boosting achieved the best result for the Blackhole dataset: 0.31%. WSS, Bagging, Stacking, and Boosting all achieved 0% for the Flooding and TDMA datasets. WSS performed the best in terms of positive predictive rate for the All_attacks and Blackhole datasets, at 98.95% and 98.78%, respectively (Figure 5E). WSS and Boosting had the best result for the Grayhole dataset: with 98.48%, while WSS, Stacking, and Boosting achieved the best result of approximately 100% for the Flooding dataset. WSS and Bagging had the best result for the TDMA dataset: 99.85%. Bagging achieved the best results for the All_attack, Grayhole, and Flooding datasets with 0.252, 0.09, and 0.108 s in terms of processing time, while WSS had the best results for the Blackhole and TDMA datasets, at 0.015 and 0.0165 s, respectively (Figure 5F). Stacking had the worst results for all datasets in terms of processing time: 6.22, 2.95, 2.03, 3.27, and 3.29 s for the All_attacks, Blackhole, Grayhole, Flooding, and TDMA datasets, respectively. We argue that the complexity introduced by the Stacking ensemble structure is one of the reasons that influences its processing time. Bagging had the best results for average prediction per sample with the All_attacks, Grayhole, and Flooding datasets, at 2.025, 3.11, and 3.56 useconds, respectively, followed by WSS at 3.277, 4.46, and 5.35 useconds, respectively (Figure 5G). WSS had the best prediction time per sample for the Blackhole and TDMA datasets, at 1.19 and 1.33 useconds, respectively. This paper's key findings can be summarized as follows:  
* The original dataset was divided into multiple binary balanced datasets to simplify the classifications and reduce the cost of computation and memory before the data preprocessing phase to avoid multi-class issues. * Two independent feature selection techniques, Kendall's correlation coefficient, and MI, can be used to determine feature-reduced datasets. [PERSON]'s correlation works best with ordinal variables, and Mutual Information measures the relevance between each individual feature and the class labels so that the features with the highest predictive ability have larger mutual information values. Reducing the number of features minimizes the model's learning time substantially and improves the classifier's performance.