Machine Learning Techniques for Energy Efﬁciency and Anomaly Detection in Hybrid Wireless Sensor Networks

: Wireless sensor networks (WSNs) are among the most popular wireless technologies for sensor communication purposes nowadays. Usually, WSNs are developed for speciﬁc applications, either monitoring purposes or tracking purposes, for indoor or outdoor environments, where limited battery power is a main challenge. To overcome this problem, many routing protocols have been proposed through the last few years. Nevertheless, the extension of the network lifetime in consideration of the sensors capacities remains an open issue. In this paper, to achieve more efﬁcient and reliable protocols according to current application scenarios, two well-known energy efﬁcient protocols, i.e., Low-Energy Adaptive Clustering hierarchy (LEACH) and Energy–Efﬁcient Sensor Routing (EESR), are redesigned considering neural networks. Speciﬁcally, to improve results in terms of energy efﬁciency, a Levenberg–Marquardt neural network (LMNN) is integrated. Furthermore, in order to improve the performance, a sub-cluster LEACH-derived protocol is also proposed. Simulation results show that the Sub-LEACH with LMNN outperformed its competitors in energy efﬁciency. In addition, the end-to-end delay was evaluated, and Sub-LEACH protocol proved to be the best among existing strategies. Moreover, an intrusion detection system (IDS) has been proposed for anomaly detection based on the support vector machine (SVM) approach for optimal feature selection. Results showed a 96.15% accuracy—again outperforming existing IDS models. Therefore, satisfactory results in terms of energy efﬁciency, end-to-end delay and anomaly detection analysis were attained. and Y.K.; resources,Y.K. and S.N.; data curation, M.M.; writing—original draft preparation, M.M.; writing—review and editing, R.P.d.P. and J.E.M.-E., Y.K. and S.N.; visualization, M.M. and S.N.; supervision, Y.K. and S.N.; project administration, M.M. and R.P.d.P.; funding acquisition, R.P.d.P. and J.E.M.-E. authors


Introduction
Wireless sensor networks (WSNs) are among the most popular wireless communication networks, where sensor nodes represent the main backbone [1,2]. WSNs can have homogeneous or heterogeneous sensors in terms of configurations, varying from hundreds to thousands in number. Most WSNs are designed for a specific application, and generally, their sensor nodes present some basic functionalities such as sensing, processing, computation and communication. The communication is mainly done with the neighboring nodes considering electromagnetic signals via radio frequency [3]. Besides this, a base station (BS) is typically found at a specified location in the WSN infrastructure, acting like a centralized node where the sensor nodes transmit their monitored data.
WSNs are application-based communication networks-i.e., according to a specific application, sensors are deployed in the monitoring field and the communication network is built. WSNs are usually deployed in wide-open regions for both monitoring and tracking purposes [4]. Examples of monitoring applications can be found in patient health monitoring, the chemical industry for toxic gas monitoring and the rubber industry. Besides, tracking applications such as pet tracking, wild species tracking and man tracking can be cited for WSN technologies. Recently released hardware has included micro-electromechanical systems (MEMS) [5,6]. The technology for WNSs has drastically changed in recent times, providing more innovative platforms for cost-effective and more efficient communication networks.
Sensor nodes (SNs) can detect, decipher and send radio frequency information [7,8]. WSNs have barely any base station (BS) nodes. They have a wide range of uses, such as weather monitoring, front-line tracking, substance detection for compound smoke examination and monitoring in clinics (patients at risk) [9,10]. Additionally, WSNs are by and large useful in inaccessible and unfriendly conditions where human intercession does not or cannot occur, for checking and tracking purposes. Checking purposes include gaseous tension observation and concoction vapor observation; and tracking purposes include animal tracking and human tracking [11,12]. Figure 1 represents the basic general architecture of the WSNs that are faced in this work. Specifically, the architecture is shown for hierarchical clustering-based protocols. Freen colored sensor nodes act as cluster head nodes (CH), and the yellow colored ones are basic sensor nodes for sensing the data. These basic nodes are also known as non-cluster head nodes (N-CH). The blue colored lines show the connectivity between cluster head nodes, and the BS [13]. It can be appreciated that the BS is the main node where all sensed data are aggregated via all sensor nodes. These arrangement of nodes in CH and N-CH generally gives a more efficient network, and the network lifetime persists more than in competing architectures. The communication is typically conducted via radio signals in a way that the ubiquity of nodes can be guaranteed. Emitted signals are listened to by all neighboring nodes, but sensors only respond if the node ID is embedded in the message, discarding the message otherwise.
In this context, the coordinating protocol can be considered as the crux for managing all functionalities, such as sensing data, aggregating data, controlling overheads, control and management of messages, query generation and developing transmission strategies [14][15][16].

Contribution
In this regard, the following contributions are pointed out in this work as follows:

1.
First of all, energy efficient sensor routing hierarchical protocols Low-Energy Adaptive Clustering Hierarchy (LEACH) and Energy-Efficient Sensor Routing (EESR) were selected as ground techniques for the proposal. To enhance the energy efficiency of these strategies, embed LEACH and EESR protocols with a Levenberg-Marquardt neural network (LMNN), i.e., LEACH-LMNN and EESR-LMNN, were developed.

2.
For further enhancement of performance in LEACH protocol, the sub-cluster LEACH protocol is proposed and embedded with a Levenberg-Marquardt neural network (LMNN), i.e., Sub-LEACH-LMNN.

3.
Additionally, as an anomaly detection system (IDS), a novel framework is proposed. This framework classifies normal and anomaly for input data, and considers the machine learning technique support vector machine (SVM) with this aim.
This paper can be summarized as follows. Section 2 presents an introduction to LEACH, EESR and sub-cluster LEACH protocols, and Section 3 studies related works in the area. Section 4 discusses the detailed Levenberg-Marquardt neural network approach and step by step implementations of LEACH, sub-cluster LEACH, EESR with the Levenberg-Marquardt neural network and IDS (proposed in this work). Section 5 explains experimental results for energy efficiency, and end-to-end delay for LEACH, LEACH-LMNN, Sub-LEACH, Sub-LEACH-LMNN, EESR and EESR-LMNN. Additionally, in Section 5, IDS experimental results are discussed in comparison to existing models. Finally, Section 6 provides conclusive remarks of the research work.

LEACH Protocol
On the one hand, LEACH protocol is a hierarchical protocol that executes on the basis of clusters. A cluster represents the grouping of various sensor nodes deployed at a specific location and it is set on the basis of some defined parameters for specific applications. The cluster consists of a limited number of sensors that disseminate their data to a BS. The whole idea behind it is to reduce the data traffic towards the BS and enhance the network lifetime. Therefore, LEACH supports the clustering approach to provide an energy efficient environment. The cluster is just a clubbing of neighboring sensor nodes sensing and aggregating data. The leader sensor of each cluster is known as cluster head (CH) and other existing nodes in a particular cluster are known as non-cluster head (N-CH) nodes. Therefore, all the nodes monitor their data in a specific time-span, which is regulated by Time Division Multiplexing Access (TDMA). Then the sensed data are disseminated to their cluster head, in a process known as data aggregation. After completion of data aggregation, all collected data are first compressed and then forwarded to the BS either directly, if the CH node is 1 hop distant from BS, and otherwise via intermediate nodes. This whole process reduces the energy consumption rate to a great extent.
For every sensor, its election as CH in LEACH protocol can be calculated with certain probability denoted as P i (S n ) at the beginning of round r + 1.
where N denotes total nodes, P denotes the probability of a node to be selected as CH, E denotes the energy and S n denotes a sensor node. For selection as CH node, the calculation of probability for each sensor node i is evaluated in Equation (2): In Equation (2), r denotes rounds accomplished, and C i (S n ) = 0 is denoted as CH. If the remaining energy is higher, then only one node can be selected as the CH node. It is calculated that after N k rounds, all sensor nodes are selected as the CH node once in their lifetimes. The term ∑ N i=1 C i (t) = 1 helps to check the eligibility of a node to be elected as the CH node.
Equation (4) shows the energy distribution.
The above expression is based on the assumption that all nodes have the same energy level. Now for CH selection based on different energy levels, Equation (5) is considered.
Hence, from Equation (7), the total higher energy of CH node can be calculated.
Additionally, the expected energy can be calculated by Equation (8) for nr as CH nodes and N − nr as N-CH nodes.
From Equation (5): Since E 0 > ( E 0 − E CH ), this expression can be simplified: (r < N n ) represents the estimated probability of each node of becoming a CH.

EESR Routing Protocol
EESR protocol [17,18] is a popular routing protocol mainly used for constructive infrastructure-based communication. It generally supports densely deployed sensor monitoring field. For implementation, the BS is situated at the center of network and the sensor nodes are scattered over the field. The field is divided into quadrants and there is a categorization into 4 quadrants: left upper, right upper, left lower and right lower. These quadrants are also denoted as (+, +), (+, −), (−, +) and (−, −). Each quadrant is further divided into equal parts as shown in Figure 2. The green node is denoted as BS, which is situated at the center. Manager nodes are shown in red color, and they are fixed at the diagonal axis in each quadrant. Yellow nodes are sensor nodes that are used for sensing the data [19,20]. The field is further divided into sectors as shown in Figure 2 with blue lines. The sectors designate the distance from BS to field far apart. This division based on hop-wise distance [21,22]. Either the CH node is 1 hop or more than 1 hop distant from BS; the data are collected accordingly. The manage nodes play vital roles in the network for collecting the data to their neighboring nodes and transferring data to the BS. The sensor nodes that are situated in each quadrant 1 hop distant to BS are not required to send data first to manager node; nodes can directly send data to the BS [23]. If sensor nodes are further than 1 hop, then sensor nodes must transmit their aggregated data to the neighboring manager nodes, and finally, manager nodes transfer the data to BS [24][25][26]. If sensor nodes are situated in the 2nd sector but they are distant from the 2nd sector manager node, then the sensor node has no need to send data first to the 2nd position manager node, it can send data to a neighboring sensor node, which acts as an intermediate node, and then that node transmit the data to the neighboring manager node [27,28]. Hence, it is not necessary to send the data to the manager node, thereby reducing the energy consumption [29,30].

Sub-Cluster LEACH
As studied above, LEACH protocol [13][14][15]31,32] is a traditional energy efficient protocol based on a hierarchical approach. However, to make it more energy efficient and reduce the complexity of data transmission, sub-clustering can be introduced. As in LEACH protocol, for a particular round, the network is divided into clusters and clusters aggregate the data, and later on aggregated data are transmitted to the BS. This task is accomplished by performing clusters, denoting some sensor nodes as CH nodes and N-CH nodes, as introduced before. Nevertheless, a major problem is related to battery consumption of CH nodes after each round. The energy drains to extreme level in some occasions, in a way that a node gets to a dead state. To change this situation, sub-clustering within the cluster can stabilize the depletion of energy up to some extent. In a particular round, each cluster has one CH node but now two more nodes will be selected within a cluster. This is done on the basis of remain energy parameter. These sub-cluster nodes are denoted as sub-cluster heads (Sub-CH), and their number is restricted to two for each cluster. They aggregate the data from corresponding nodes and compress them. This is totally dependent on the distance from the CH node or Sub-CH node. The distance is calculated with link quality parameter. If the distance from the CH node is far greater than from a Sub-CH, then N-CH will transfer the monitored data to the Sub-CH node, and otherwise directly towards the CH node. The data aggregated at the Sub-CH node are compressed and forwarded to the CH node. Later, aggregated data at the CH nodes are sent directly from N-CH nodes and Sub-CH nodes, jointly transmitted to BS as shown in Figure 3.
The idea of the sub-cluster can be summarized as follows: 1. Select one, or at most two Sub-CH nodes in each cluster.

2.
Selection depends on remain energy parameter and nodes concentration. 3.
N-CH selects either CH or Sub-CH nodes of the same cluster to transfer the data. This can be done by distance calculations from N-CH to CH and N-CH to Sub-CH. 4.
The link quality parameter is used to calculate the distance.

5.
Each N-CH transmits its data to CH nodes or Sub-CH nodes. The Sub-CH node, later, transmits the aggregated data to CH by compressing them. 6.
Data are collected by CH from N-CH and Sub-CH nodes. 7.
Jointly, N-CH data and Sub-CH data are transferred to the BS. 8.
A Sub-CH node also acts as an intermediate node for transmitting the aggregated data from CH nodes to BS, only if the Sub-CH node is nearer to BS. Otherwise, another N-CH node is selected as the intermediate. However, first priority is given to the Sub-CH node as an intermediate node.

Related Works
The Low-Energy Adaptive Clustering Hierarchy (LEACH) protocol [13][14][15]31,32] emerged under the hierarchical based approach. The nature of this protocol is to create a cluster-based computation for data aggregation, processing and transmission in order to reduce the energy consumption of sensor nodes. To be precise, the specific reason for the development of LEACH was to overcome the depletion rate of sensor node's energy to some extent. LEACH is more efficient in comparison to other traditional algorithms, such as MTE and direct diffusion. Later, Centralized Low Energy Adaptive Clustering Hierarchy (LEACH-C) was proposed, which is a modified version of the LEACH protocol. In this protocol, during the initialization of parameters for each round, every sensor node transfers its location and energy level status to the BS [15]. Then the BS evaluates the average energy level of the network and sorts of out nodes that have high energy level that can be selected as CH for next very round. Further, for uniform distribution of the cluster, the LEACH Energy Betweenness (LEACH-EB) model was proposed [31]. It performs well in terms of improving network lifetime and reliability. LEACH-EB uses minimum variance in the calculation of energy betweenness for improving the clustering performance. This helps in balancing the energy consumption for each sensor node in the network. Due to this fact, CH selection is done in a more distributive form; i.e., each cluster has a uniform number of N-CH nodes. This helps the CH node to deplete its energy after a round in the uniform rate; otherwise some CH nodes deplete energy very quickly due to more considered N-CH nodes, and the overall energy levels of the CH and N-CH nodes are balanced. The energy efficiency is enhanced relatively in comparison to LEACH protocol. Furthermore, the LEACH-E protocol uses minimum spanning tree approach for enhancement of the overall network lifetime [32]. LEACH-E performs better than the LEACH protocol. The remaining energy of the CH is key parameter for selection process in LEACH-E. In addition to this, IBLEACH is introduced as another energy efficient protocol [33]. An extra phase is embedded between twp phases, i.e., the pre-stage phase. It is introduced in between the cluster setup phase and the steady phase. This phase tries to reduce the energy consumption notably. Additionally, LEACH-EX was proposed as a modified version of LEACH-E [34]. In this protocol, the authors tried to modify the threshold function to get a better response and prolong the network lifetime to a greater extent. For better performance, the LEACH protocol can be implemented with artificial intelligence techniques. LEACH-GA integrates a genetic algorithm into the LEACH protocol to get more energy efficient protocol [35]. In this protocol, an extra phase called the preparation phase is installed during the execution of the first round. This phase helps the selection of CH nodes in terms of optimal values of each CH probability. Every round, all three phases are executed. After every round, the end optimal value is calculated, which helps in the selection of the CH node for the next round. This is how LEACH-GA minimizes the energy consumption, by optimizing the selection of the CH node from all N-CH nodes each round [36].

Levenberg-Marquardt Neural Network
The Levenberg-Marquardt neural network (LMNN) is a fast learning neural network. As shown in Figure 4, LMNN (pointed out as LM) outperforms close competitors such as the scaled conjugate gradient (SCG) back propagation algorithm and the one-step secant backpropagation (OSS) algorithm. Particularly, this figure evaluates the convergence speed on the sensor data, and tries to demonstrate the learning efficiency of the diverse strategies, justifying the considered selection. Additionally, the OSS algorithm required less storage capacity for computation, and it did not store the complete Hessian matrix. However, it needed more storage capacity for computations in terms of epochs when compared to SCG algorithm or LM. Hence, LMNN is capable of faster processing and computation than its close competitors, and thus, it was selected in this work.
The Hessian matrix is calculated as follows: where H is the Hessian matrix, J is the Jacobian matrix and µ represents the combination coefficient. Equation (12) represents updated Levenberg-Marquardt algorithm.
The Algorithm 1 for LMNN is presented as follows.
Step 1 Compute F k + F(X k ) and J k + J(X k ).
Step 2 (a) Obtain d 1k by solving the following linear system (b) Solve the linear system to obtain d 2k , where y k = x k + d 1k .
(c) Solve the linear system Step 3 If then take α k and go to Step 5. Otherwise go to step 4.
Step 5 Set x k+1 = x k + α k d k . Set k = k + 1 and goto step 1.

The Proposed LEACH-LMNN Protocol
In this section, the proposed LEACH protocol with the LMNN approach is described. The flow-chart is shown in Figure 5. From Figure 5, it can be observed that the execution starts from the BS, where it generates the query for data from the established sensor network. The network checks whether it is the first round or not. If it is the first round of execution, the network will not calculate the energy for each sensor node, since all sensors have same level of energy. Thus, it directly jumps to the cluster head selection step, and the Levenberg-Marquardt neural network is embedded to select the CH node on the basis of remaining energy and concentration of nodes. Hence, in the first round only, the remaining energy parameter will not be considered for CH selection. After CH selection, the data aggregation process starts, where all N-CH nodes transfer their monitored data to the CH node. This aggregation of data is executed with specific time span with the help of TDMA. Therefore, all data are stored at CH nodes. In the steady stage, all CH nodes transfer their data to the BS via intermediate node or directly if they are in range of BS. In addition to this, information related to each node either CH node or N-CH node is calculated and compared with threshold energy. If a node energy exceeds the declared threshold energy, the node is alive; otherwise the node is dead. The network maintains a list of all nodes with information related to alive or dead states, and also maintains a record of CH nodes. Once a node is selected as the CH node, the next rounds will not give them priority to be selected as a CH node, in order to reduce the energy of the node to a greater extent. Further, in every round it is also checked whether the last node is dead or not. If the last node is dead, then the algorithm is stopped, since the network is dead. Specifically, last node dead (LND) checks whether the algorithm is completed or not. This is all the step by step description for the LEACH-LMNN approach proposed in this work. Results will be discussed in Section 4.

The Proposed Sub-Cluster LEACH-LMNN Protocol
The proposed sub-cluster LEACH protocol with LMNN approach is explained stepwise. The flow-chart of proposed protocol is shown in Figure 6. In this proposal, some amendments in LEACH-LMNN are introduced to enhance the performance of the network in terms of energy and end-to-end delay. From Figure 6, it can be observed that the starting steps are similar to the previous LEACH-LMNN approach. In this protocol, the major improvement is the incorporation of a sub-cluster CH selection. The key idea is to consider, after the CH node selection with Levenberg-Marquardt neural network, that all the CH nodes could further select one or two nodes in their vicinity. These nodes are called subcluster CH nodes, and they act in support of the main CH node. For instance, if there are 10 nodes in a particular cluster, one acts as CH node, and the rest could act as N-CH nodes. These nine N-CH nodes transfer their control messages, data, etc., to a single CH node only in the first step of the proposed strategy. Hence, in order to reduce this burden, another one or two nodes are selected with the Levenberg-Marquardt neural network as sub-cluster CH or, in short, Sub-CH nodes. N-CH nodes are divided between CH nodes and N-CH nodes on the basis of distance. The distance is calculated with a link quality parameter. Therefore, some nodes will transfer data to the CH node in its cluster, and others will transfer data to Sub-CH nodes. After data aggregation, Sub-CHs will transfer their data to the CH node, which will further jointly transfer to the BS. The obtained results are presented in Section 4.

Proposed EESR-LMNN Protocol
In this section, the proposed EESR protocol with the LMNN approach is introduced. The flow-chart of the proposed protocol is shown in Figure 7. Firstly, the protocol setup requires the initialization of the diverse parameters. Then, the BS generates the query for data from the network. If the network is executing for the first time, it is assumed that the network energy is at the highest rate, and thus, the step for calculation sensor energy is skipped. Then the sensor nodes start sensing data for the specified time span considering TDMA. Secondly, when the data are gathered at the sensor nodes, all the sensor nodes start transmitting the data to the BS via intermediate nodes or nearer manager nodes. A traditional EESR is followed. However, to make this protocol more efficient, the LMNN approach is used, founded on a neural network. The LMNN approach helps in the selection of the most feasible path towards the manager nodes. In all four quadrants, the manager nodes are strongly connected to other manager nodes. Henceforth, the LMNN approach stabilizes the connectivity between manager nodes and smooths the manager-manger communication. The sensor nodes to manager nodes communication is totally dependent on the distances among them. Sensor-to-sensor connectivity is usually followed by transmission of data towards the nearest manager nodes. The nearest situated sensor nodes to manager nodes are strongly connected, and transmission of data tasks is accomplished, and nearest sensor-to-manager communication is also triggered in a smooth way by the LMNN approach. Thirdly, when the data are aggregated in the nearest manager nodes, the data are transferred to BS via manager-to-manager communication. This phase is also called the steady phase. Fourthly, after the whole data transmission is completed, the sensor node energy is checked. Obviously, due to the execution of all involved processes, the energy depletes to some extent. Therefore, the energy of each sensor node is compared to the threshold energy (threshold energy is the minimum energy required to take part in communication for next round). If the energy of the sensor node is greater than the threshold value, its ID is saved as an alive node, and it is able to take part in next round. Otherwise, the node is declared as a dead node. Finally, the list of nodes is updated. Based on this information, the next round starts until the last node is dead. Results of this proposed protocol are also presented and discussed in Section 4 as follows.

Proposed Intrusion Detection System
Intrusion detection systems (IDS) have the ability to track malicious activity over a whole network. It is introduced into a wireless sensor network to check for any unusual activity during control transmission and data transmission. The intruder tries to attack the network to block the transmission or steal precious information from the network. The intruder embeds bugs into a network by breaking the security of the network and unbalancing the activities in the sensor network. To overcome this problem, a strong secured framework is needed to save the system from malicious attacks. Figure 8 shows the proposed framework for anomaly detection.
The proposed framework consists of various steps to detect anomalies. First of all, data are collected from the network, which undergo pre-processing. After the pre-processing, it needs to detect the missing values in the system and then replace the null values with some values. By default, average values are considered. Thereafter, duplicate values are eliminated from the dataset. Next, data normalization and a data encoding process are performed. The encoded data goes through a dimensional reduction process to help the data handling. Thus, feature optimization is done to grab the optimal features from the data, which helps detecting anomaly in the data.

Data Sensors
Pre-processing

Selection of Optimal Features
Optimal feature selection plays a vital role in the detection of anomalies in the dataset. It also help with reducing the computational cost for the given data. The entropy can be calculated from the equation below: where p represents the probability of a class label in a given dataset. For the evaluation of anomaly detection in this research work, after optimal feature selection, a SVM regressor is suggested for anomaly detection in a wireless sensor network. Experimental results are discussed in the following section.

Experimental Results for LEACH-LMNN, EESR-LMNN and Sub-Cluster LEACH-LMNN
In this section, the simulation setup and results for the diverse proposals in this work are presented. The network was created in MATALB (2009b), and the considered initialization parameters for the network are shown in Table 1. For energy calculation, the required energy model is shown in Figure 9. In this figure, the energy dissipation at transmission and receiver both are shown. To transmit a packet of K bits at a distance d, the energy consumption is given by Equations (21) and (22). Control packet length 200 bits Figure 9. Energy model.
where d 0 is evaluated as  Figures 12 and 13, the end-to-end delay evaluation for the various protocols is also presented, also showing the more efficient performance of Sub − LEACH − LMNN protocol for this criterion.

Routing Protocol Discussion
Hence, at it can be observed, the proposed Sub − LEACH − LMNN protocol outperformed the others in both considered fields, i.e., 100 m × 100 m and 200 m × 200 m. This means that Sub − LEACH − LMNN works efficiently, and it is robust by nature for two differentiated representative areas. Furthermore, considering these two different areas, the network lifetime has been analyzed in terms of last node dead (LND). Figure 14 shows that the 100 m × 100 m area gave better results than the 200 m × 200 m area for each protocol-specifically, LEACH (1068), Sub-LEACH (1620), EESR (1666), LEACH-LMNN (1625), EESR − LMNN (1695) and Sub-LEACH-LMNN (1760). This means that the 200 m × 200 m area allowed for less network lifetime than the 100 m × 100 m area. Since the number of sensor nodes was fixed, i.e., 100 in both fields, this result was expected and let us evaluate the protocol's efficiency in different field sizes. Therefore, in both scenarios the Sub − LEACH − LMNN outperformed the rest of the strategies in terms of energy efficiency and end-to-end delay.

IDS Results
For experimentation of the performance of the proposal, we have considered a wellknown standard dataset, i.e., NSLKDD data-set [37], which is freely available and mostly used for intrusion detection problems. It has 148517 instances and 42 attributes, including the class label. It also has 22 types of attacks. In NSLKDD dataset the considered number of normal packets was 77,054, and the number of anomaly packets was 71,463, giving a total of 148,517 packets. In total, 70% of data were used for training and 30% for testing. Specifically, the training data dimensions were 103,961 packets, and the testing dataset dimensions were 44,556 packets.
Diverse performance metrics were considered to evaluate the suggested solution, including precision, recall, F1-measure and accuracy. These performance metrics are based on true positive (TP), false positive (FP), false negative (FN) and true negative (TN). Additionally, accuracy was employed to measure how many instances were correctly classified as regular and attacks classes. Accuracy is obtained by adding correctly classify instances with dividing the total instances, as shown in Equation (7).
Precision's objective is to evaluate the true positive (TP) entities in relation to false positive (FP) entities.
The purpose of recall is to test true positive (TP) entities in relation to (FN) false negative entities that are not at all classified.
Sometimes a performance assessment may not be efficient in terms of accuracy and recall, and the quality of the strategy is under question. This problem is solved by using F1-score that gives an average value for recall and precision. Table 2 show the results of the proposed model, where TPR and FPR stand for true positive rate and false positive rate, respectively. The results are discussed as follows.

IDS Discussion
The loss scores for training and testing were 0.11 and 0.10, respectively. The SVMbased model gave scores of 95.30% for training and 95.81% for testing, respectively. The values for precision, recall and F1-Score were 94.00%, 98.00% and 96.00%, respectively, for a normal class. On the other hand, the values for precision, recall and F1-score were 98.00%, 94.00%, and 96.00%, respectively, in the case of the anomaly class. FPR was 00.05 and TPR was 97.84%. From Table 3, it can be seen that the proposed model achieved a high TPR, and also achieved a superior FPR in comparison to other existing studies. Table 3. Comparison of the proposed model and other approaches.

Conclusions
WSNs are generally densely deployed in specific fields for monitoring required parametric values. The major aim of any wireless sensor network is prolonging overall network lifetime as much as possible. Therefore, energy efficiency is a high priority parameter for any sensor network, and thus, any efficient management needs to be focused on it. In this paper, two quality of services-based parameters such as energy efficiency and end-to-end delay were considered for the evaluation of the proposed protocols. Specifically, the main contribution of the work with regard to authors' previous work can be summarized as follows: in other to increase the lifetime of the network, the Levenberg-Marquardt neural network was embed into well-known energy efficient strategies: LMNN approach was implemented in LEACH, Sub-LEACH and EESR protocols, as shown in Figures 10-14. Simulation results showed that Sub-LEACH-LMNN outperforms the competing algorithms in terms of both energy and end-to-end criteria. Additionally, as a second contribution of the work, this paper worked toward anomaly detection: SVM was used to classify normal and anomaly classes, also showing higher accuracy compared to other existing models. Therefore, our management of a network with energy efficiency and security is suggested, and our results are extensible to the diverse base technologies such as IEEE 802.15.4 and ZIG BEE, by merely changing basic configurations in the simulation parameters. Specifically, the IDS proposed model achieved a 96.15% TPR and a 5.11% FPR, improving the rates by 85.00% and 5.43%, respectively, given by the best of its competitors. In future works, more sophisticated algorithms based on machine learning techniques will be integrated to obtain a more energy efficient and cost-effective protocol.

Conflicts of Interest:
The authors declare no conflict of interest.