# Artificial Neural Network-Based Mechanism to Detect Security Threats in Wireless Sensor Networks
## 5 Results and Discussion
These matrices have the following mathematical formulation [32]:  
\[DR\;or\;TPR=\frac{\textit{TP}}{\textit{TP}+\textit{FN}} \tag{12}\]  
The number of correctly identified attacks divided by the total number of attacks yields the detection rate (_DR_). It is extremely rare for a classifier to obtain a _TPR_ of 1, which indicates that every intrusion is successfully recognized. \[FPR=\frac{\textit{FP}}{\textit{FP}+\textit{TN}} \tag{13}\]  
The number of normal instances that are classified as attacks (_FP_) is divided by the total number of normal instances to obtain the _FPR_. \[Accuracy=\frac{\textit{TP}+\textit{TN}}{\textit{TP}+\textit{TN}+\textit{FP}+ \textit{FN}} \tag{14}\]  
Accuracy, also known as classification rate (CR), measures how well the classifier can distinguish between normal and anomalous traffic behavior. It is calculated as a percentage \begin{table}
\begin{tabular}{c c c c c c c} \hline \hline
**S.No** & **Class** & _DR_ & _FPR_ & _Precision_ & _F1 Score_ & _Accuracy_ \\ \hline
1 & Normal & 99.34 & 0.43 & 99.62 & 99.48 & \\
2 & B.H & 99.08 & 0.50 & 98.82 & 98.95 & \\
3 & G.H & 99.13 & 0.50 & 98.89 & 99.01 & 99.49 \\
4 & W.H & 99.29 & 0.50 & 99.71 & 99.50 & \\
5 & Average & 99.21 & 0.48 & 99.26 & 99.23 & \\ \hline \hline \end{tabular}
\end{table} 
Table 6: Performance evaluation of the proposed system. \begin{table}
\begin{tabular}{l c c c c} \hline \hline
**Detail** & **Training** & **Validation** & **Testing** & **Total** \\ \hline Normal & 4250 & 550 & 810 & 5610 \\ Black-hole & 3580 & 485 & 760 & 4825 \\ Gray-hole & 3550 & 475 & 720 & 4745 \\ Wormhole & 3620 & 490 & 710 & 4820 \\ Total & **15,000** & **2000** & **3000** & **20,000** \\ \hline \hline \end{tabular}
\end{table} 
Table 4: Distribution of input vectors in the dataset. \begin{table}
\begin{tabular}{c c c c c c} \hline \hline  & \multicolumn{5}{c}{**Predicted Class**} \\ \cline{2-5}  & **S.No** & **Classes** & **Normal** & **B.H** & **G.H** & **W.H** \\ \cline{2-5}  & **1** & **Normal** & **806** & **1** & **2** & **1** \\ \cline{2-5}  & **2** & **B.H** & **1** & **755** & **3** & **1** \\ \cline{2-5}  & **3** & **G.H** & **1** & **2** & **716** & **1** \\ \cline{2-5}  & **4** & **W.H** & **1** & **1** & **3** & **705** \\ \cline{2-5}  & **Precision** & 99.63 & 99.47 & 98.90 & **99.58** \\ \hline \hline \end{tabular}
\end{table} 
Table 5: Confusion Matrix. by dividing the total number of occurrences properly classified using baseline behavior features by all instances. \[Precision=\frac{TP}{TP+FP} \tag{15}\]  
Precision measures how well a classifier makes positive predictions. For a given class, it is computed as the ratio of true positives to the total of true positives and false positives. \[F1 Score=2*\frac{(DR*Precision)}{(DR+Precision)} \tag{16}\]  
The \(F1\)_Score_ provides a balance between precision and \(DR\) by taking the harmonic mean of these two criteria. This score is used when it is desirable to take into account false positives and false negatives equally. Table 7 and Figure 13 show the performance analysis of the proposed system. It has been noted that practically every kind of attack is appropriately classified. Feature selection results in the fewest incorrect classifications, yet the proposed system performs better than other detection methods, as shown by the analysis in Figure 14. This analysis compares the detection rate of different routing attacks by the proposed system with that of a technique proposed in [32] and those of machine-learning techniques like support-vector machines (SVM), DT, and RF. It is observed from the results that the maximum detection performance is attained by the proposed approach. The average detection rate of the proposed model is 99.21%, which is 1.38% greater than that of the approach proposed in [32], i.e., 97.8%. With regard to other machine-learning approaches, the average detection rate of our proposed system was 34.9%, 24.16%, and 31.26% better than the detection rates of SVM, DT, and RF, respectively, as shown in Table 8 and Figure 15.