# Trust in Intrusion Detection Systems: An Investigation of Performance Analysis for Machine Learning and Deep Learning Models

Authors: Basim Mahbooba; Radhya Sahal; Wael Alosaimi; Martin Serrano
Journal: Complexity
 (2021)

---

## Abstract

To design and develop AI-based cybersecurity systems (e.g., intrusion detection system (IDS)), users can justifiably trust, one needs to evaluate the impact of trust using machine learning and deep learning technologies. To guide the design and implementation of trusted AI-based systems in IDS, this paper provides a comparison among machine learning and deep learning models to investigate the trust impact based on the accuracy of the trusted AI-based systems regarding the malicious data in IDs. The four machine learning techniques are decision tree (DT), K nearest neighbour (KNN), random forest (RF), and naïve Bayes (NB). The four deep learning techniques are LSTM (one and two layers) and GRU (one and two layers). Two datasets are used to classify the IDS attack type, including wireless sensor network detection system (WSN-DS) and KDD Cup network intrusion dataset. A detailed comparison of the eight techniques’ performance using all features and selected features is made by measuring the accuracy, precision, recall, and F1-score. Considering the findings related to the data, methodology, and expert accountability, interpretability for AI-based solutions also becomes demanded to enhance trust in the IDS.


---

## Body

## 1. Introduction

Cybersecurity system is developed based on different peers including technology, processes, and people. The relationships among these peers are the core of the trust management in the cybersecurity. For example, (1) the relationship between people and groups, (2) the relationship between people and organizations, and (3) the relationship between people and technology. The trusted peers are deployed in the cybersecurity system which aims to detect the cyberattacks [1].Artificial intelligence (AI) defines a set of techniques that simulates the human intelligence in machines. The core idea of these techniques is extracting the knowledge from a collection of data. Consequently, there is no certain grantee level to trust the AI-based techniques due to the three aspects: (1) quality of data, (2) the degree of complexity for the methodology that was used to design the AI systems, and (3) AI engineer’s experiences. According to the context of this work, a set of peers of AI technologies can be interacted to perform the trust for the cybersecurity systems. Therefore, we cannot do trust AI technologies to prevent the cybersecurity systems against cyberattacks. Consequently, this work in this paper study the trust for AI-based solutions including machine learning and deep learning in cybersecurity systems considering (1) data, (2) methodology, and (3) expert accountability. To do so, we will investigate AI-based solutions for trust context of cybersecurity in terms of the quality of data, methodologies, and experiences.


### 1.1. Trust in Intrusion Detection Systems

Cybersecurity system is developed based on different peers, including technology, processes, and people. The relationships among these peers are the core of the trust management in the cybersecurity. For example, (1) the relationship between people and groups, (2) the relationship between people and organizations, and (3) the relationship between people and technology. The trusted peers are deployed in the cybersecurity system to detect the cyberattacks [1].“Trust” is commonly used word in cybersecurity which describes the connection a foundation that must be established for cybersecurity systems including machine-to-machine (M2M) system. In M2M systems, trust can be defined as the confidence between machines to identify and manage their information technology assets. To achieve the trust chain between machines, cryptography, digital signatures, electronic certificates, and AI-based solutions are used. As these techniques are established to perform trust for M2M systems, trust seems like a simple function; it is often a fundamental challenge. In particular, the challenge of trust in cybersecurity is a broader notion about the quality of information being exchanged among machines, the methodologies used to design these techniques, and the expert accountability that use these techniques. According to this work, we will investigate AI-based solutions for trust context of cybersecurity. Many efforts have been made in research and industry to prevent the critical system from the cyberattacks. The IDS have received attention due to the continuously increasing cost to fight cybercrime [2]. The cybercrime type includes (1) malicious insiders, (2) denial of services, and (3) web-based attacks. Therefore, most companies and enterprises deploy cybersecurity systems (e.g., antivirus, firewall, and IDS).The core function of the IDS is identifying the malicious attacks’ activities in advanced before they access the information and harm the confidentiality of the critical systems [3]. This demand of the security systems from both known and unknown threats opens a challenge for the research communities and industry to design secure and trustful systems against the cyberattacks [4]. This also opens up the issue about how to successfully secure from both known and unknown threats. There is no straightforward answer to this because of the increasing number of threats every year [4]. Recently, AI-based technologies, including machine learning and deep learning, play a vital role in learning from the previous attacks’ collected historical data. These models’ extracted knowledge is used to enhance the trust in IDS [5].


### 1.2. Contribution

Our main contributions are summarized as follows:We develop investigation methodology to study the trust impact in intrusion detection, including the data, methodology, and expert accountability by analyzing machine learning and deep learning models’ performanceCollect intrusion detection using wireless sensor network detection system (WSN-DS) and KDD Cup network intrusion datasetApply different feature engineering techniques, including correlation matrixCompare four machine learning (DT, KNN, RF, and NB) and deep learning (LSTM and GRU, using one and two layers) to study the trusted AI-based systems’ accuracy regarding the malicious data to detect any intrusion in the system


### 1.3. Paper Organization

The rest of this paper is organized as follows. A review of relevant works is conducted in Section2. The methodology is provided in Section 3. The experiments and results are described in Section 4. The discussion is introduced in Section 5. Finally, the paper is concluded in Section 6.


## 1.1. Trust in Intrusion Detection Systems

Cybersecurity system is developed based on different peers, including technology, processes, and people. The relationships among these peers are the core of the trust management in the cybersecurity. For example, (1) the relationship between people and groups, (2) the relationship between people and organizations, and (3) the relationship between people and technology. The trusted peers are deployed in the cybersecurity system to detect the cyberattacks [1].“Trust” is commonly used word in cybersecurity which describes the connection a foundation that must be established for cybersecurity systems including machine-to-machine (M2M) system. In M2M systems, trust can be defined as the confidence between machines to identify and manage their information technology assets. To achieve the trust chain between machines, cryptography, digital signatures, electronic certificates, and AI-based solutions are used. As these techniques are established to perform trust for M2M systems, trust seems like a simple function; it is often a fundamental challenge. In particular, the challenge of trust in cybersecurity is a broader notion about the quality of information being exchanged among machines, the methodologies used to design these techniques, and the expert accountability that use these techniques. According to this work, we will investigate AI-based solutions for trust context of cybersecurity. Many efforts have been made in research and industry to prevent the critical system from the cyberattacks. The IDS have received attention due to the continuously increasing cost to fight cybercrime [2]. The cybercrime type includes (1) malicious insiders, (2) denial of services, and (3) web-based attacks. Therefore, most companies and enterprises deploy cybersecurity systems (e.g., antivirus, firewall, and IDS).The core function of the IDS is identifying the malicious attacks’ activities in advanced before they access the information and harm the confidentiality of the critical systems [3]. This demand of the security systems from both known and unknown threats opens a challenge for the research communities and industry to design secure and trustful systems against the cyberattacks [4]. This also opens up the issue about how to successfully secure from both known and unknown threats. There is no straightforward answer to this because of the increasing number of threats every year [4]. Recently, AI-based technologies, including machine learning and deep learning, play a vital role in learning from the previous attacks’ collected historical data. These models’ extracted knowledge is used to enhance the trust in IDS [5].


## 1.2. Contribution

Our main contributions are summarized as follows:We develop investigation methodology to study the trust impact in intrusion detection, including the data, methodology, and expert accountability by analyzing machine learning and deep learning models’ performanceCollect intrusion detection using wireless sensor network detection system (WSN-DS) and KDD Cup network intrusion datasetApply different feature engineering techniques, including correlation matrixCompare four machine learning (DT, KNN, RF, and NB) and deep learning (LSTM and GRU, using one and two layers) to study the trusted AI-based systems’ accuracy regarding the malicious data to detect any intrusion in the system


## 1.3. Paper Organization

The rest of this paper is organized as follows. A review of relevant works is conducted in Section2. The methodology is provided in Section 3. The experiments and results are described in Section 4. The discussion is introduced in Section 5. Finally, the paper is concluded in Section 6.


## 2. Related Work

Vinayakumar et al. [6] have used a deep neural network to develop IDS to predict unforeseen and unpredictable cyberattacks. Almomani et al. [7] have used artificial neural network (ANN) to develop IDS to classify different DoS attacks. The authors in [8] have used a multistage machine learning-based intrusion detection to detect and classify four types of jamming attacks. Abhale and Manivannan [9] have used different types of supervised machine learning to classify anomaly type of IDS. On the other hand, Alqahtani et al. [10] have proposed genetic-based extreme gradient boosting (XGBoot) to detect minority classes of attacks in highly imbalanced data traffics of wireless sensor networks. The authors in [11] have introduced an ensemble learning scheme for classifying network intrusion detection. However, Farrahi and Ahmadzadeh [12] have used various algorithms such as k-means clustering, Naïve Bayes, support vector machine, and OneR algorithms to classify regular traffic and DoS attack. Also, the genetic algorithm (GA) was implemented to detect the different types of intrusions [13].Some researchers have used feature selection methods to select essential features will reduce the computational time of the algorithms. Due to network data’s significant features, many IDS were developed with feature selection [14]. Chebrolu et al. [15] classified primary elements in constructing IDS that is very crucial for real-world intrusion detection. Zaman and Karray [16] implemented a feature selection technique to construct a lightweight IDS. Vimalkumar and Radhika [17] implemented principal component analysis- (PCA-) based feature selection technique in the big data framework for IDS. Balakrishnan et al. [18] developed an IDS model with a gain ratio as a feature selection technique. Most of the IDS-based studies focused on the performance of the implemented model. Alkasassbeh et al. [19] concentrate on different types of attack, such as http flood, smurf, siddos, and udp flood. They implemented various machine learning algorithms to detect DOS intrusions and demonstrated the high accuracy of 98.36% using multilevel perceptron (MLP). Peng et al. [20] proposed an IDS system based on a decision tree to improve detection efficiency. Their method showed better performance over Naïve Bayesian and KNN methods.


## 3. Research Methodology

This section will describe our approach to investigate the trust impact in intrusion detection using machine learning and deep learning models. To do so, five phases are developed including (1) data collection to describe the datasets and their characteristics, (2) splitting datasets, (3) feature extraction methods, (4) optimization and training models, and (5) the evaluation metrics that will be used [19] for performance comparison (see Figure 1). Further details about the developed phases are described as follows.Figure 1
The workflow of developed machine learning and deep learning models.


### 3.1. Data Collection

In this section, we provide a description of the datasets used to find the optimal machine learning model and deep learning model that obtains the best performance for attack type classification in IDS. Two datasets were collected from wireless sensor network detection system (WSN-DS) and KDD Cup network intrusion dataset.


#### 3.1.1. WSN-DS Dataset

The first dataset is WSN-DS which is a specialized dataset for detecting intrusions in wireless sensor networks. The WSN-DS dataset is collected by [7] to help better detect and classify types of denial-of-service (DoS) attacks. According to this work, we have used the WSN-DS dataset to study the machine learning and deep learning models performances with respect to the sensor nodes that can be able to detect attacks’ patterns from the normal traffic. Then, we have compared the machine learning and deep learning models’ performances to study the impact of trust in machine learning and deep learning models’ IDS.The WSN-DS dataset contains 23 features extracted using LEACH routing protocol includingId, Time, Is_CH, who_CH, RSSI, Dist_To_CH, M_D_CH, A_D_CH, ADV_S, ADV_R, JOIN_S, JOIN_R, ADV_SCH_S, ADV_SCH_R, Rank, DATA_S, DATA_R, Data_Sent_BS, Dist_CH_BS, Send_code, Current_Energy, Consumed_Energy, and Attack_Type [7].The dataset file has only 19 features including the class label [10]. These 19 features were Id, Time, Is_CH, who_CH, Dist_To_CH, ADV_S, ADV_R, JOIN_S, JOIN_R, ADV_SCH_S, ADV_SCH_R, Rank, DATA_S, DATA_R, Data_Sent_BS, Dist_CH_BS, Send_code, Consumed_Energy, and Attack_Type. The number of samples within the WSN-DS dataset is 374,662. These samples are distributed among five main groups of which four of them are types of DoS attack which are labeled as attacks including Blackhole, Grayhole, Flooding, and Scheduling attacks and Normal. The description of the attacks is as follows (see Table 1):Blackhole attack: type of DoS attack where the attacker advertises itself at the beginning of the round to affect the LEACH protocolGrayhole attack: type of DoS attack where the attacker advertises itself as a CH for other nodes to affect the LEACH protocolFlooding attack: type of DoS attack where the attacker advertises itself by sending a large number of advertising CH messages to affect the LEACH protocolScheduling attack: type of DoS attack where the attacker acts as a CH and assigns all nodes the same time slot to send data during the setup phase of the LEACH protocolNormal: it means no threatTable 1
Types of attack in WSN datasets.
Types of attackQuantityProportion (%)Normal34006790.77Grayhole145973.90Blackhole100502.68Scheduling66391.77Flooding33130.88Furthermore, Table2 shows a set of descriptive statistics of the WSN-DS dataset using a set of statistical functions including count, mean, std, min, and max. We have ignored Id because it has been used to provide a unique symbolized number of the sensor node and no sense for compute statistics for it. Therefore, 18 features will be used in the next phases.Table 2
Statistical analysis of WSN-DS dataset.
Feature NoFeature nameCountMeanstdmin25%50%75%Max1Time3746611064.749899.646250353803150336002Is_CH3746610.1157660.319945000013who_CH374661274980.4389911.210100010709611607221507334021004Dist_To_CH37466122.5993821.9557904.7354418.3726133.776214.27465ADV_S3746610.2676982.0611480000976ADV_R3746616.9405627.04431903571177JOIN_S3746610.7799050.414311011118JOIN_R3746610.7374934.69149800001249SCH_S3746610.2889842.75474600009910SCH_R3746610.7474520.4344750011111Rank3746619.68710414.6819013139912DATA_S37466144.8579242.57446013356224113DATA_R37466173.89004230.24630000149614Data_Sent_To_BS3746614.56944819.67916000024115dist_CH_To_BS37466122.5627450.26160000201.934916send_code3746612.4979572.40733701241517Consumed energy3746610.3056610.66946200.056150.097970.2177645.0939418Attack type3746612.8806150.56495803334


#### 3.1.2. KDD Dataset

The second dataset is KDD Cup network intrusion dataset (http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.htmachine learning). The data comes from DARPA 98 Intrusion Detection Evaluation by Lincoln laboratory at MIT. According to [21], these datasets were collected using multiple computers connected to the Internet to model a small US Air Force base of qualified personnel by using several simulated intrusions. According to this work, we have used KDD dataset to study the machine learning and deep learning models’ performances concerning the sensor nodes that can detect attack patterns from the normal traffic. We then compared the machine learning and deep learning models’ performances to study the impact of trust in machine learning and deep learning models’ IDS. There are 42 attributes used in this dataset. The number of samples in the KDD dataset is 311,029. These samples are distributed among five main groups. Four of them are labeled as attacks including Denial of Service, User to Root Remote-to-local, and PROBING and Normal. The description of the attacks is as follows (see Table 3):Denial-of-service (DOS) attack: it is done by illegal users causing resource constraint for the targeted systems. Consequently, the targeted system is being unable to provide efficient services to the legal users.User to root (U2R) attack: the attacker belongs to the same group which tries to access the root of the system using a normal account within the network.Remote to local (R2L) attack: the remote user has no account to access a specific node within the network. The attacker tries to gain local access by sending packets to explore any vulnerabilities within the network.Probe attack (Probe): the attacker collects data about the network configuration to discover vulnerabilities and then accesses the network by loopholes.Normal: it means no threat.Table 3
Types of attack in KDD datasets.
Types of attackQuantityProportion (%)Denial of service (DOS)22985373.90Remote to local (R2L)161895.2User to root (U2R)2280.07PROBING (probe)41661.34Normal6059319.48Furthermore, Table4 shows a set of descriptive statistics of the KDD dataset using a set of statistical functions including count, mean, std, min, and max.Table 4
Statistical analysis of KDD dataset.
Feature NoFeature nameCountMeanStdMin25%50%75%Max1Duration43988021.55854538.91390000583292protocol_type4398800.4140520.543742000123Service43988022.2570212.970220141422654Flag4398808.0953651.8038680999105src_bytes4398803322.34210472470179103210326.93E + 086dst_bytes439880878.577234494.07000051554687Land4398804.32E−050.006572000018wrong_fragment4398800.0065020.135425000039Urgent4398801.59E−050.005840000310hot4398800.0368760.81443700003011num_failed_logins4398800.0001680.0163780000512logged_in4398800.1466850.3537920000113num_compromised4398800.0109191.899432000088414root_shell4398800.0001020.0101140000115su_attempted4398803.41E−050.0075390000216num_root4398800.011862.124426000099317num_file_creations4398800.0010750.09706600002818num_shells4398800.0001090.0110790000219num_access_files4398800.0009210.0355090000820num_outbound_cmds439880000000021is_host_login439880000000022is_guest_login4398800.0014340.0378470000123Count439880348.345209.268013251051151124srv_count439880312.4045242.582901251051151125serror_rate4398800.1967420.3968460000126srv_serror_rate4398800.1966530.3971850000127rerror_rate4398800.0156260.1218980000128srv_rerror_rate4398800.015920.1231880000129same_srv_rate4398800.8128050.3735610111130diff_srv_rate4398800.0183270.0780250000131srv_diff_host_rate4398800.0282920.1401830000132dst_host_count439880232.817564.40408025525525525533dst_host_srv_count439880196.4258101.7786017825525525534dst_host_same_srv_rate4398800.7837950.39296500.9711135dst_host_diff_srv_rate4398800.023710.0894180000.01136dst_host_same_src_port_rate4398800.6334630.4739770011137dst_host_srv_diff_host_rate4398800.0066770.0430430000138dst_host_serror_rate4398800.1968060.3967290000139dst_host_srv_serror_rate4398800.1964910.3971160000140dst_host_rerror_rate4398800.0162850.1206390000141dst_host_srv_rerror_rate4398800.0156240.1204530000142Attacktype4398800.203540.44241400004


### 3.2. Splitting Dataset

In this step, the WSN-DS and KDD datasets are split into 30% training dataset and 70% testing dataset. The training set is fed into the machine learning/deep learning models to let models learn from this data, while the unseen test set is used to evaluate machine learning/deep learning models. Table5 and Table 6 present the number of instances in these two sets for WSN-DS and KDD datasets, respectively.Table 5
The WSN-DS dataset separated 70% training set and 30% testing set.
Attack typeTraining set (70%)Testing set (30%)Normal25504985017Grayhole109473649Blackhole75372512Scheduling49781660Flooding2484828Sum28099593666Table 6
The KDD dataset separated 70% training set and 30% testing set.
Attack typeTraining set (70%)Testing set (30%)Dos249609106896Normal5482623590Probe26721125R2l784341U2r2512Sum307916131964


### 3.3. Feature Extraction

The key benefit of using feature selection methods is determining the relevant feature in the dataset. Therefore, feature selection is necessary for the machine learning and deep learning processes since sometimes irrelevant features affect the models’ performance. According to this work context, feature selection enhances the classification accuracy of the attack types and reduces the model execution time. Also, we have used correlation matrix andp value to reduce the features that have less significance in the classified attack and affect the models’ performances.


#### 3.3.1. WSN-DS Dataset

For WSN-DS dataset, we have used a correlation matrix for feature analysis to calculate each feature’s relations with other features within the dataset as depicted in Figure2. It can be seen that the features within the WSN-DS datasets do not have high correlations. We have removed only one feature, and then, we have calculated the p values for the rest 17 features.Figure 2
Correlation matrix between features for WSN dataset.As the attack type will be classified by machine learning and deep learning models, Table7 presents the p values of the 17 features to choose the high correlated features for machine learning and deep learning models. Consequently, the features which have the correlation with attack type above 0.005 have been selected to be fitted in machine learning and deep learning models. In particular, 6 features have been selected based on their high correlations such as Time, Dist_To_CH, JOIN_R, Rank, DATA_S, and send_code and their p values are 7.00E−93, 1.47E −24, 5.93E−06, 0.009842, 1.31E −32, and 2.44E −125, respectively.Table 7
Feature selection of WSN dataset usingp values.
Feature NoFeature namep valueStatistically significant1Time7.00E−93Yes2Is_CH0No3who_CH0No4Dist_To_CH1.47E−24Yes5ADV_S0No6ADV_R0No7JOIN_S0No8JOIN_R5.93E−06Yes9SCH_S0No10SCH_R0No11Rank0.009842Yes12DATA_S1.31E−32Yes13DATA_R0No14Data_Sent_To_BS0No15dist_CH_To_BS0No16send_code2.44E−125Yes17Consumed energy0No


#### 3.3.2. KDD Dataset

For KDD dataset, we have also used a correlation matrix for feature analysis to calculate each feature’s relations with other features within the dataset. We found that the features within the WSN-DS datasets do not have high correlations. We have removed 12 features, and then, we have calculated thep values for the rest 30 features.As the attack type will be classified by machine learning and deep learning models, Table8 presents the pvalues of the 30 features to choose the high correlated features for machine learning and deep learning models. Consequently, the features which have the correlation with attack type above 0.005 have been selected to be fitted in machine learning and deep learning models. In particular, 14 features have been selected based on their high correlations such as duration, service, src_ bytes, land, urgent, hot, num_compromised, su_attempted, num_file_creations, num_shells, num_access_files, num outbound_cmds, is_host_login, and srv_diff_host_rate and their p values are 2.33E − 60, 0.604708, 1.34E − 68, 9.51E −128, 0.402631, 5.01E −230, 2.69E −43, 2.45E −21, 3.48E −11, 9.85E −43, 6.50E −26, 0.043069, 0.039867, and 1.56E −70, respectively.Table 8
Feature selection of KDD dataset usingp values.
Feature NoFeature namep valueStatistically significant1Duration2.33E − 60Yes2Service0.604708Yes3src_bytes1.34E − 68Yes4Land9.51E − 128Yes5Urgent0.402631Yes6hot5.01E − 230Yes7num_compromised2.69E − 43Yes8su_attempted2.45E − 21Yes9num_file_creations3.48E − 11Yes10num_shells9.85E − 43Yes11num_access_files6.50E − 26Yes12num_outbound_cmds0.043069Yes13is_host_login0.039867Yes14srv_diff_host_rate1.56E − 70Yes15protocol_type0No16Flag0No17dst_bytes0No18wrong_fragment0No19num_failed_logins0No20logged_in0No21root_shell0No22is_guest_login0No23Count0No24serror_rate0No25rerror_rate0No26same_srv_rate0No27diff_srv_rate0No28dst_host_count0No29dst_host_diff_srv_rate0No30dst_host_srv_diff_host_rate0No


### 3.4. Machine Learning and Deep Learning Models

Regular machine learning models used in this paper are decision tree (DT), K nearest neighbour (KNN), random forest (RF), and naïve Bayes (NB). Moreover, among deep learning algorithms, we analyze the performance of LSTM (one and two layers) and GRU (one and two layers).


### 3.5. Optimization and Training Models

In this section, two categories of optimization and training models will be presented, including machine learning and deep learning.


#### 3.5.1. Regular Machine Learning Models

(1) K-Fold Cross-Validation. The dataset is divided into k equal size of the sections in which the k-1 group is used to train the classifiers, and the remaining part is used to test the performance in each stage. The validation process is repeated k times. The output of the classifier is estimated based on the k tests. Various k values are selected for CV. In our analysis, we used k = 10, the 10-fold CV process, 70% of the data for training, and 30% of the data for testing purposes.(2) Hyperparameter Tuning. It is used to pass various parameters to the model. Grid search is the most widely used method for hyperparameter tuning. Initially, the user defines a set of values for each hyperparameter. The model then tests all values for each hyperparameter and selects the best value to achieve the best performance result.


#### 3.5.2. Deep Learning Models

For hyperparameters optimization, we have used a Keras Tuner library to pick the optimal set of hyperparameters in hidden layers (LSTM or GRU) and dropout layers. We set different values for different parameters, which are the number of neurons, reg_rate for l2 regularization technique [22], and the dropout rate for the dropout layers [23]. For this, we have applied the Keras Tuner on the training dataset to select the best parameters, as shown in Table 9.Table 9
Hyperparameters’ configurations selected by Keras Tuner.
ParameterThe valueDropout rateWithin the range of 0.1 rate to 0.5 rateThe number of neuronsWithin the range of 10 neuron to 200 neuronsRegularization l20.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5


### 3.6. Evaluating Models

Seven standard metrics were utilized to evaluate the models’ accuracy, precision, recall, and F1-score. TP is true positive, TN is true negative, FP is false positive, and FN is a false negative. We will consider four metrics for our experimental results, including accuracy, precision, recall, and F1-score.


## 3.1. Data Collection

In this section, we provide a description of the datasets used to find the optimal machine learning model and deep learning model that obtains the best performance for attack type classification in IDS. Two datasets were collected from wireless sensor network detection system (WSN-DS) and KDD Cup network intrusion dataset.


### 3.1.1. WSN-DS Dataset

The first dataset is WSN-DS which is a specialized dataset for detecting intrusions in wireless sensor networks. The WSN-DS dataset is collected by [7] to help better detect and classify types of denial-of-service (DoS) attacks. According to this work, we have used the WSN-DS dataset to study the machine learning and deep learning models performances with respect to the sensor nodes that can be able to detect attacks’ patterns from the normal traffic. Then, we have compared the machine learning and deep learning models’ performances to study the impact of trust in machine learning and deep learning models’ IDS.The WSN-DS dataset contains 23 features extracted using LEACH routing protocol includingId, Time, Is_CH, who_CH, RSSI, Dist_To_CH, M_D_CH, A_D_CH, ADV_S, ADV_R, JOIN_S, JOIN_R, ADV_SCH_S, ADV_SCH_R, Rank, DATA_S, DATA_R, Data_Sent_BS, Dist_CH_BS, Send_code, Current_Energy, Consumed_Energy, and Attack_Type [7].The dataset file has only 19 features including the class label [10]. These 19 features were Id, Time, Is_CH, who_CH, Dist_To_CH, ADV_S, ADV_R, JOIN_S, JOIN_R, ADV_SCH_S, ADV_SCH_R, Rank, DATA_S, DATA_R, Data_Sent_BS, Dist_CH_BS, Send_code, Consumed_Energy, and Attack_Type. The number of samples within the WSN-DS dataset is 374,662. These samples are distributed among five main groups of which four of them are types of DoS attack which are labeled as attacks including Blackhole, Grayhole, Flooding, and Scheduling attacks and Normal. The description of the attacks is as follows (see Table 1):Blackhole attack: type of DoS attack where the attacker advertises itself at the beginning of the round to affect the LEACH protocolGrayhole attack: type of DoS attack where the attacker advertises itself as a CH for other nodes to affect the LEACH protocolFlooding attack: type of DoS attack where the attacker advertises itself by sending a large number of advertising CH messages to affect the LEACH protocolScheduling attack: type of DoS attack where the attacker acts as a CH and assigns all nodes the same time slot to send data during the setup phase of the LEACH protocolNormal: it means no threatTable 1
Types of attack in WSN datasets.
Types of attackQuantityProportion (%)Normal34006790.77Grayhole145973.90Blackhole100502.68Scheduling66391.77Flooding33130.88Furthermore, Table2 shows a set of descriptive statistics of the WSN-DS dataset using a set of statistical functions including count, mean, std, min, and max. We have ignored Id because it has been used to provide a unique symbolized number of the sensor node and no sense for compute statistics for it. Therefore, 18 features will be used in the next phases.Table 2
Statistical analysis of WSN-DS dataset.
Feature NoFeature nameCountMeanstdmin25%50%75%Max1Time3746611064.749899.646250353803150336002Is_CH3746610.1157660.319945000013who_CH374661274980.4389911.210100010709611607221507334021004Dist_To_CH37466122.5993821.9557904.7354418.3726133.776214.27465ADV_S3746610.2676982.0611480000976ADV_R3746616.9405627.04431903571177JOIN_S3746610.7799050.414311011118JOIN_R3746610.7374934.69149800001249SCH_S3746610.2889842.75474600009910SCH_R3746610.7474520.4344750011111Rank3746619.68710414.6819013139912DATA_S37466144.8579242.57446013356224113DATA_R37466173.89004230.24630000149614Data_Sent_To_BS3746614.56944819.67916000024115dist_CH_To_BS37466122.5627450.26160000201.934916send_code3746612.4979572.40733701241517Consumed energy3746610.3056610.66946200.056150.097970.2177645.0939418Attack type3746612.8806150.56495803334


### 3.1.2. KDD Dataset

The second dataset is KDD Cup network intrusion dataset (http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.htmachine learning). The data comes from DARPA 98 Intrusion Detection Evaluation by Lincoln laboratory at MIT. According to [21], these datasets were collected using multiple computers connected to the Internet to model a small US Air Force base of qualified personnel by using several simulated intrusions. According to this work, we have used KDD dataset to study the machine learning and deep learning models’ performances concerning the sensor nodes that can detect attack patterns from the normal traffic. We then compared the machine learning and deep learning models’ performances to study the impact of trust in machine learning and deep learning models’ IDS. There are 42 attributes used in this dataset. The number of samples in the KDD dataset is 311,029. These samples are distributed among five main groups. Four of them are labeled as attacks including Denial of Service, User to Root Remote-to-local, and PROBING and Normal. The description of the attacks is as follows (see Table 3):Denial-of-service (DOS) attack: it is done by illegal users causing resource constraint for the targeted systems. Consequently, the targeted system is being unable to provide efficient services to the legal users.User to root (U2R) attack: the attacker belongs to the same group which tries to access the root of the system using a normal account within the network.Remote to local (R2L) attack: the remote user has no account to access a specific node within the network. The attacker tries to gain local access by sending packets to explore any vulnerabilities within the network.Probe attack (Probe): the attacker collects data about the network configuration to discover vulnerabilities and then accesses the network by loopholes.Normal: it means no threat.Table 3
Types of attack in KDD datasets.
Types of attackQuantityProportion (%)Denial of service (DOS)22985373.90Remote to local (R2L)161895.2User to root (U2R)2280.07PROBING (probe)41661.34Normal6059319.48Furthermore, Table4 shows a set of descriptive statistics of the KDD dataset using a set of statistical functions including count, mean, std, min, and max.Table 4
Statistical analysis of KDD dataset.
Feature NoFeature nameCountMeanStdMin25%50%75%Max1Duration43988021.55854538.91390000583292protocol_type4398800.4140520.543742000123Service43988022.2570212.970220141422654Flag4398808.0953651.8038680999105src_bytes4398803322.34210472470179103210326.93E + 086dst_bytes439880878.577234494.07000051554687Land4398804.32E−050.006572000018wrong_fragment4398800.0065020.135425000039Urgent4398801.59E−050.005840000310hot4398800.0368760.81443700003011num_failed_logins4398800.0001680.0163780000512logged_in4398800.1466850.3537920000113num_compromised4398800.0109191.899432000088414root_shell4398800.0001020.0101140000115su_attempted4398803.41E−050.0075390000216num_root4398800.011862.124426000099317num_file_creations4398800.0010750.09706600002818num_shells4398800.0001090.0110790000219num_access_files4398800.0009210.0355090000820num_outbound_cmds439880000000021is_host_login439880000000022is_guest_login4398800.0014340.0378470000123Count439880348.345209.268013251051151124srv_count439880312.4045242.582901251051151125serror_rate4398800.1967420.3968460000126srv_serror_rate4398800.1966530.3971850000127rerror_rate4398800.0156260.1218980000128srv_rerror_rate4398800.015920.1231880000129same_srv_rate4398800.8128050.3735610111130diff_srv_rate4398800.0183270.0780250000131srv_diff_host_rate4398800.0282920.1401830000132dst_host_count439880232.817564.40408025525525525533dst_host_srv_count439880196.4258101.7786017825525525534dst_host_same_srv_rate4398800.7837950.39296500.9711135dst_host_diff_srv_rate4398800.023710.0894180000.01136dst_host_same_src_port_rate4398800.6334630.4739770011137dst_host_srv_diff_host_rate4398800.0066770.0430430000138dst_host_serror_rate4398800.1968060.3967290000139dst_host_srv_serror_rate4398800.1964910.3971160000140dst_host_rerror_rate4398800.0162850.1206390000141dst_host_srv_rerror_rate4398800.0156240.1204530000142Attacktype4398800.203540.44241400004


## 3.1.1. WSN-DS Dataset

The first dataset is WSN-DS which is a specialized dataset for detecting intrusions in wireless sensor networks. The WSN-DS dataset is collected by [7] to help better detect and classify types of denial-of-service (DoS) attacks. According to this work, we have used the WSN-DS dataset to study the machine learning and deep learning models performances with respect to the sensor nodes that can be able to detect attacks’ patterns from the normal traffic. Then, we have compared the machine learning and deep learning models’ performances to study the impact of trust in machine learning and deep learning models’ IDS.The WSN-DS dataset contains 23 features extracted using LEACH routing protocol includingId, Time, Is_CH, who_CH, RSSI, Dist_To_CH, M_D_CH, A_D_CH, ADV_S, ADV_R, JOIN_S, JOIN_R, ADV_SCH_S, ADV_SCH_R, Rank, DATA_S, DATA_R, Data_Sent_BS, Dist_CH_BS, Send_code, Current_Energy, Consumed_Energy, and Attack_Type [7].The dataset file has only 19 features including the class label [10]. These 19 features were Id, Time, Is_CH, who_CH, Dist_To_CH, ADV_S, ADV_R, JOIN_S, JOIN_R, ADV_SCH_S, ADV_SCH_R, Rank, DATA_S, DATA_R, Data_Sent_BS, Dist_CH_BS, Send_code, Consumed_Energy, and Attack_Type. The number of samples within the WSN-DS dataset is 374,662. These samples are distributed among five main groups of which four of them are types of DoS attack which are labeled as attacks including Blackhole, Grayhole, Flooding, and Scheduling attacks and Normal. The description of the attacks is as follows (see Table 1):Blackhole attack: type of DoS attack where the attacker advertises itself at the beginning of the round to affect the LEACH protocolGrayhole attack: type of DoS attack where the attacker advertises itself as a CH for other nodes to affect the LEACH protocolFlooding attack: type of DoS attack where the attacker advertises itself by sending a large number of advertising CH messages to affect the LEACH protocolScheduling attack: type of DoS attack where the attacker acts as a CH and assigns all nodes the same time slot to send data during the setup phase of the LEACH protocolNormal: it means no threatTable 1
Types of attack in WSN datasets.
Types of attackQuantityProportion (%)Normal34006790.77Grayhole145973.90Blackhole100502.68Scheduling66391.77Flooding33130.88Furthermore, Table2 shows a set of descriptive statistics of the WSN-DS dataset using a set of statistical functions including count, mean, std, min, and max. We have ignored Id because it has been used to provide a unique symbolized number of the sensor node and no sense for compute statistics for it. Therefore, 18 features will be used in the next phases.Table 2
Statistical analysis of WSN-DS dataset.
Feature NoFeature nameCountMeanstdmin25%50%75%Max1Time3746611064.749899.646250353803150336002Is_CH3746610.1157660.319945000013who_CH374661274980.4389911.210100010709611607221507334021004Dist_To_CH37466122.5993821.9557904.7354418.3726133.776214.27465ADV_S3746610.2676982.0611480000976ADV_R3746616.9405627.04431903571177JOIN_S3746610.7799050.414311011118JOIN_R3746610.7374934.69149800001249SCH_S3746610.2889842.75474600009910SCH_R3746610.7474520.4344750011111Rank3746619.68710414.6819013139912DATA_S37466144.8579242.57446013356224113DATA_R37466173.89004230.24630000149614Data_Sent_To_BS3746614.56944819.67916000024115dist_CH_To_BS37466122.5627450.26160000201.934916send_code3746612.4979572.40733701241517Consumed energy3746610.3056610.66946200.056150.097970.2177645.0939418Attack type3746612.8806150.56495803334


## 3.1.2. KDD Dataset

The second dataset is KDD Cup network intrusion dataset (http://kdd.ics.uci.edu/databases/kddcup99/kddcup99.htmachine learning). The data comes from DARPA 98 Intrusion Detection Evaluation by Lincoln laboratory at MIT. According to [21], these datasets were collected using multiple computers connected to the Internet to model a small US Air Force base of qualified personnel by using several simulated intrusions. According to this work, we have used KDD dataset to study the machine learning and deep learning models’ performances concerning the sensor nodes that can detect attack patterns from the normal traffic. We then compared the machine learning and deep learning models’ performances to study the impact of trust in machine learning and deep learning models’ IDS. There are 42 attributes used in this dataset. The number of samples in the KDD dataset is 311,029. These samples are distributed among five main groups. Four of them are labeled as attacks including Denial of Service, User to Root Remote-to-local, and PROBING and Normal. The description of the attacks is as follows (see Table 3):Denial-of-service (DOS) attack: it is done by illegal users causing resource constraint for the targeted systems. Consequently, the targeted system is being unable to provide efficient services to the legal users.User to root (U2R) attack: the attacker belongs to the same group which tries to access the root of the system using a normal account within the network.Remote to local (R2L) attack: the remote user has no account to access a specific node within the network. The attacker tries to gain local access by sending packets to explore any vulnerabilities within the network.Probe attack (Probe): the attacker collects data about the network configuration to discover vulnerabilities and then accesses the network by loopholes.Normal: it means no threat.Table 3
Types of attack in KDD datasets.
Types of attackQuantityProportion (%)Denial of service (DOS)22985373.90Remote to local (R2L)161895.2User to root (U2R)2280.07PROBING (probe)41661.34Normal6059319.48Furthermore, Table4 shows a set of descriptive statistics of the KDD dataset using a set of statistical functions including count, mean, std, min, and max.Table 4
Statistical analysis of KDD dataset.
Feature NoFeature nameCountMeanStdMin25%50%75%Max1Duration43988021.55854538.91390000583292protocol_type4398800.4140520.543742000123Service43988022.2570212.970220141422654Flag4398808.0953651.8038680999105src_bytes4398803322.34210472470179103210326.93E + 086dst_bytes439880878.577234494.07000051554687Land4398804.32E−050.006572000018wrong_fragment4398800.0065020.135425000039Urgent4398801.59E−050.005840000310hot4398800.0368760.81443700003011num_failed_logins4398800.0001680.0163780000512logged_in4398800.1466850.3537920000113num_compromised4398800.0109191.899432000088414root_shell4398800.0001020.0101140000115su_attempted4398803.41E−050.0075390000216num_root4398800.011862.124426000099317num_file_creations4398800.0010750.09706600002818num_shells4398800.0001090.0110790000219num_access_files4398800.0009210.0355090000820num_outbound_cmds439880000000021is_host_login439880000000022is_guest_login4398800.0014340.0378470000123Count439880348.345209.268013251051151124srv_count439880312.4045242.582901251051151125serror_rate4398800.1967420.3968460000126srv_serror_rate4398800.1966530.3971850000127rerror_rate4398800.0156260.1218980000128srv_rerror_rate4398800.015920.1231880000129same_srv_rate4398800.8128050.3735610111130diff_srv_rate4398800.0183270.0780250000131srv_diff_host_rate4398800.0282920.1401830000132dst_host_count439880232.817564.40408025525525525533dst_host_srv_count439880196.4258101.7786017825525525534dst_host_same_srv_rate4398800.7837950.39296500.9711135dst_host_diff_srv_rate4398800.023710.0894180000.01136dst_host_same_src_port_rate4398800.6334630.4739770011137dst_host_srv_diff_host_rate4398800.0066770.0430430000138dst_host_serror_rate4398800.1968060.3967290000139dst_host_srv_serror_rate4398800.1964910.3971160000140dst_host_rerror_rate4398800.0162850.1206390000141dst_host_srv_rerror_rate4398800.0156240.1204530000142Attacktype4398800.203540.44241400004


## 3.2. Splitting Dataset

In this step, the WSN-DS and KDD datasets are split into 30% training dataset and 70% testing dataset. The training set is fed into the machine learning/deep learning models to let models learn from this data, while the unseen test set is used to evaluate machine learning/deep learning models. Table5 and Table 6 present the number of instances in these two sets for WSN-DS and KDD datasets, respectively.Table 5
The WSN-DS dataset separated 70% training set and 30% testing set.
Attack typeTraining set (70%)Testing set (30%)Normal25504985017Grayhole109473649Blackhole75372512Scheduling49781660Flooding2484828Sum28099593666Table 6
The KDD dataset separated 70% training set and 30% testing set.
Attack typeTraining set (70%)Testing set (30%)Dos249609106896Normal5482623590Probe26721125R2l784341U2r2512Sum307916131964


## 3.3. Feature Extraction

The key benefit of using feature selection methods is determining the relevant feature in the dataset. Therefore, feature selection is necessary for the machine learning and deep learning processes since sometimes irrelevant features affect the models’ performance. According to this work context, feature selection enhances the classification accuracy of the attack types and reduces the model execution time. Also, we have used correlation matrix andp value to reduce the features that have less significance in the classified attack and affect the models’ performances.


### 3.3.1. WSN-DS Dataset

For WSN-DS dataset, we have used a correlation matrix for feature analysis to calculate each feature’s relations with other features within the dataset as depicted in Figure2. It can be seen that the features within the WSN-DS datasets do not have high correlations. We have removed only one feature, and then, we have calculated the p values for the rest 17 features.Figure 2
Correlation matrix between features for WSN dataset.As the attack type will be classified by machine learning and deep learning models, Table7 presents the p values of the 17 features to choose the high correlated features for machine learning and deep learning models. Consequently, the features which have the correlation with attack type above 0.005 have been selected to be fitted in machine learning and deep learning models. In particular, 6 features have been selected based on their high correlations such as Time, Dist_To_CH, JOIN_R, Rank, DATA_S, and send_code and their p values are 7.00E−93, 1.47E −24, 5.93E−06, 0.009842, 1.31E −32, and 2.44E −125, respectively.Table 7
Feature selection of WSN dataset usingp values.
Feature NoFeature namep valueStatistically significant1Time7.00E−93Yes2Is_CH0No3who_CH0No4Dist_To_CH1.47E−24Yes5ADV_S0No6ADV_R0No7JOIN_S0No8JOIN_R5.93E−06Yes9SCH_S0No10SCH_R0No11Rank0.009842Yes12DATA_S1.31E−32Yes13DATA_R0No14Data_Sent_To_BS0No15dist_CH_To_BS0No16send_code2.44E−125Yes17Consumed energy0No


### 3.3.2. KDD Dataset

For KDD dataset, we have also used a correlation matrix for feature analysis to calculate each feature’s relations with other features within the dataset. We found that the features within the WSN-DS datasets do not have high correlations. We have removed 12 features, and then, we have calculated thep values for the rest 30 features.As the attack type will be classified by machine learning and deep learning models, Table8 presents the pvalues of the 30 features to choose the high correlated features for machine learning and deep learning models. Consequently, the features which have the correlation with attack type above 0.005 have been selected to be fitted in machine learning and deep learning models. In particular, 14 features have been selected based on their high correlations such as duration, service, src_ bytes, land, urgent, hot, num_compromised, su_attempted, num_file_creations, num_shells, num_access_files, num outbound_cmds, is_host_login, and srv_diff_host_rate and their p values are 2.33E − 60, 0.604708, 1.34E − 68, 9.51E −128, 0.402631, 5.01E −230, 2.69E −43, 2.45E −21, 3.48E −11, 9.85E −43, 6.50E −26, 0.043069, 0.039867, and 1.56E −70, respectively.Table 8
Feature selection of KDD dataset usingp values.
Feature NoFeature namep valueStatistically significant1Duration2.33E − 60Yes2Service0.604708Yes3src_bytes1.34E − 68Yes4Land9.51E − 128Yes5Urgent0.402631Yes6hot5.01E − 230Yes7num_compromised2.69E − 43Yes8su_attempted2.45E − 21Yes9num_file_creations3.48E − 11Yes10num_shells9.85E − 43Yes11num_access_files6.50E − 26Yes12num_outbound_cmds0.043069Yes13is_host_login0.039867Yes14srv_diff_host_rate1.56E − 70Yes15protocol_type0No16Flag0No17dst_bytes0No18wrong_fragment0No19num_failed_logins0No20logged_in0No21root_shell0No22is_guest_login0No23Count0No24serror_rate0No25rerror_rate0No26same_srv_rate0No27diff_srv_rate0No28dst_host_count0No29dst_host_diff_srv_rate0No30dst_host_srv_diff_host_rate0No


## 3.3.1. WSN-DS Dataset

For WSN-DS dataset, we have used a correlation matrix for feature analysis to calculate each feature’s relations with other features within the dataset as depicted in Figure2. It can be seen that the features within the WSN-DS datasets do not have high correlations. We have removed only one feature, and then, we have calculated the p values for the rest 17 features.Figure 2
Correlation matrix between features for WSN dataset.As the attack type will be classified by machine learning and deep learning models, Table7 presents the p values of the 17 features to choose the high correlated features for machine learning and deep learning models. Consequently, the features which have the correlation with attack type above 0.005 have been selected to be fitted in machine learning and deep learning models. In particular, 6 features have been selected based on their high correlations such as Time, Dist_To_CH, JOIN_R, Rank, DATA_S, and send_code and their p values are 7.00E−93, 1.47E −24, 5.93E−06, 0.009842, 1.31E −32, and 2.44E −125, respectively.Table 7
Feature selection of WSN dataset usingp values.
Feature NoFeature namep valueStatistically significant1Time7.00E−93Yes2Is_CH0No3who_CH0No4Dist_To_CH1.47E−24Yes5ADV_S0No6ADV_R0No7JOIN_S0No8JOIN_R5.93E−06Yes9SCH_S0No10SCH_R0No11Rank0.009842Yes12DATA_S1.31E−32Yes13DATA_R0No14Data_Sent_To_BS0No15dist_CH_To_BS0No16send_code2.44E−125Yes17Consumed energy0No


## 3.3.2. KDD Dataset

For KDD dataset, we have also used a correlation matrix for feature analysis to calculate each feature’s relations with other features within the dataset. We found that the features within the WSN-DS datasets do not have high correlations. We have removed 12 features, and then, we have calculated thep values for the rest 30 features.As the attack type will be classified by machine learning and deep learning models, Table8 presents the pvalues of the 30 features to choose the high correlated features for machine learning and deep learning models. Consequently, the features which have the correlation with attack type above 0.005 have been selected to be fitted in machine learning and deep learning models. In particular, 14 features have been selected based on their high correlations such as duration, service, src_ bytes, land, urgent, hot, num_compromised, su_attempted, num_file_creations, num_shells, num_access_files, num outbound_cmds, is_host_login, and srv_diff_host_rate and their p values are 2.33E − 60, 0.604708, 1.34E − 68, 9.51E −128, 0.402631, 5.01E −230, 2.69E −43, 2.45E −21, 3.48E −11, 9.85E −43, 6.50E −26, 0.043069, 0.039867, and 1.56E −70, respectively.Table 8
Feature selection of KDD dataset usingp values.
Feature NoFeature namep valueStatistically significant1Duration2.33E − 60Yes2Service0.604708Yes3src_bytes1.34E − 68Yes4Land9.51E − 128Yes5Urgent0.402631Yes6hot5.01E − 230Yes7num_compromised2.69E − 43Yes8su_attempted2.45E − 21Yes9num_file_creations3.48E − 11Yes10num_shells9.85E − 43Yes11num_access_files6.50E − 26Yes12num_outbound_cmds0.043069Yes13is_host_login0.039867Yes14srv_diff_host_rate1.56E − 70Yes15protocol_type0No16Flag0No17dst_bytes0No18wrong_fragment0No19num_failed_logins0No20logged_in0No21root_shell0No22is_guest_login0No23Count0No24serror_rate0No25rerror_rate0No26same_srv_rate0No27diff_srv_rate0No28dst_host_count0No29dst_host_diff_srv_rate0No30dst_host_srv_diff_host_rate0No


## 3.4. Machine Learning and Deep Learning Models

Regular machine learning models used in this paper are decision tree (DT), K nearest neighbour (KNN), random forest (RF), and naïve Bayes (NB). Moreover, among deep learning algorithms, we analyze the performance of LSTM (one and two layers) and GRU (one and two layers).


## 3.5. Optimization and Training Models

In this section, two categories of optimization and training models will be presented, including machine learning and deep learning.


### 3.5.1. Regular Machine Learning Models

(1) K-Fold Cross-Validation. The dataset is divided into k equal size of the sections in which the k-1 group is used to train the classifiers, and the remaining part is used to test the performance in each stage. The validation process is repeated k times. The output of the classifier is estimated based on the k tests. Various k values are selected for CV. In our analysis, we used k = 10, the 10-fold CV process, 70% of the data for training, and 30% of the data for testing purposes.(2) Hyperparameter Tuning. It is used to pass various parameters to the model. Grid search is the most widely used method for hyperparameter tuning. Initially, the user defines a set of values for each hyperparameter. The model then tests all values for each hyperparameter and selects the best value to achieve the best performance result.


### 3.5.2. Deep Learning Models

For hyperparameters optimization, we have used a Keras Tuner library to pick the optimal set of hyperparameters in hidden layers (LSTM or GRU) and dropout layers. We set different values for different parameters, which are the number of neurons, reg_rate for l2 regularization technique [22], and the dropout rate for the dropout layers [23]. For this, we have applied the Keras Tuner on the training dataset to select the best parameters, as shown in Table 9.Table 9
Hyperparameters’ configurations selected by Keras Tuner.
ParameterThe valueDropout rateWithin the range of 0.1 rate to 0.5 rateThe number of neuronsWithin the range of 10 neuron to 200 neuronsRegularization l20.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5


## 3.5.1. Regular Machine Learning Models

(1) K-Fold Cross-Validation. The dataset is divided into k equal size of the sections in which the k-1 group is used to train the classifiers, and the remaining part is used to test the performance in each stage. The validation process is repeated k times. The output of the classifier is estimated based on the k tests. Various k values are selected for CV. In our analysis, we used k = 10, the 10-fold CV process, 70% of the data for training, and 30% of the data for testing purposes.(2) Hyperparameter Tuning. It is used to pass various parameters to the model. Grid search is the most widely used method for hyperparameter tuning. Initially, the user defines a set of values for each hyperparameter. The model then tests all values for each hyperparameter and selects the best value to achieve the best performance result.


## 3.5.2. Deep Learning Models

For hyperparameters optimization, we have used a Keras Tuner library to pick the optimal set of hyperparameters in hidden layers (LSTM or GRU) and dropout layers. We set different values for different parameters, which are the number of neurons, reg_rate for l2 regularization technique [22], and the dropout rate for the dropout layers [23]. For this, we have applied the Keras Tuner on the training dataset to select the best parameters, as shown in Table 9.Table 9
Hyperparameters’ configurations selected by Keras Tuner.
ParameterThe valueDropout rateWithin the range of 0.1 rate to 0.5 rateThe number of neuronsWithin the range of 10 neuron to 200 neuronsRegularization l20.01, 0.05, 0.1, 0.2, 0.3, 0.4, 0.5


## 3.6. Evaluating Models

Seven standard metrics were utilized to evaluate the models’ accuracy, precision, recall, and F1-score. TP is true positive, TN is true negative, FP is false positive, and FN is a false negative. We will consider four metrics for our experimental results, including accuracy, precision, recall, and F1-score.


## 4. Experiments and Results

This section describes the results of applying machine learning models (DT, KNN, RF, and NB) and four deep learning models (LSTM and GRU, using one and two layers), including cross-validation results and testing results. Each model performance is discussed using two datasets, including WSN-DS and KKD.


### 4.1. Experiment Setup

The machine learning models and deep learning models which are applied on the collected datasets has been developed in Python3 using Anaconda Python 3. The experiments have been conducted using a laptop with a specification of 20 GB of RAM, 7 cores, and 100 GB disk. The machine learning models and deep learning models have been trained using 70% dataset, while the rest of 30% of dataset has been used for testing. The machine learning models have been implemented using Sklearn library, while the deep learning models have been implemented using Tensorflow and Keras packages.


### 4.2. WSN-DS Dataset

This section presents the results of applying machine learning models (DT, KNN, RF, and NB) and four deep learning models (LSTM and GRU, using one and two layers), and cross-validation results and testing results are described. Each machine learning model and deep learning model performance is discussed using full features and selected features to classify five classes of attack types, includingNormal, Grayhole, Blackhole, Scheduling, and Flooding. All the positive and negative rates results of the cross-validation and testing performances used to compute accuracy, precision, recall, and F-score matrices are presented in Tables 10–13.Table 10
The performance of machine learning for WSN dataset using all features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingDTTN99.9799.9699.9297.7499.8999.9699.9899.998.2399.89FP0.030.040.082.260.110.040.020.11.770.11FN0.944.731.80.217.11.183.111.440.236.07Accuracy99.9599.9199.8699.699.7799.9399.9599.8599.6399.78Precision98.9395.2498.1299.7794.1198.5697.3297.699.8293.74Recall99.0695.2798.299.7992.998.8296.8998.5699.7793.93F-score98.9995.2498.1699.7893.598.6997.198.0899.7993.83KNNTN99.7199.8599.5684.2599.8999.7299.999.5784.1499.89FP0.290.150.4415.750.110.280.10.4315.860.11FN10.3525.3620.580.5335.259.8222.6721.010.4936.23Accuracy99.4499.6398.7898.0699.2799.4699.7298.7598.0999.26Precision89.4681.5788.0298.4191.6889.9585.7188.3598.491.57Recall89.6574.6479.4299.4764.7590.1877.3378.9999.5163.77F-score89.5577.9483.4898.9475.990.0781.3183.4198.9675.18RFTN99.9699.9499.9598.2699.9999.9699.9699.9398.42100FP0.040.060.051.740.010.040.040.071.580FN0.461.361.420.127.230.520.891.530.126.07Accuracy99.9599.9399.8999.7399.8699.9499.9599.8799.7499.89Precision98.669498.6799.8299.5298.4595.398.399.8499.78Recall99.5498.6498.5899.8892.7799.4899.1198.4799.8893.93F-score99.0996.2698.6399.8596.0298.9697.1798.3999.8696.77NBTN99.9793.0696.498.8190.5699.9793.0596.3299.0890.26FP0.036.943.61.199.440.036.953.680.929.74FN65.6918.5753.2116.9918.3165.3120.0052.2417.4215.99Accuracy98.2192.9694.4784.4790.498.2092.9594.4084.1090.15Precision97.149.4834.5399.8513.597.078.5134.9199.8913.37Recall34.3181.4346.7983.0181.6934.6980.0047.7682.5884.01F-score50.6716.9839.7290.6523.1751.1115.3840.3390.4123.07Table 11
The performance of machine learning for WSN dataset using selected features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingDTTN99.9599.9599.997.7299.9199.9699.9699.9197.4199.91FP0.050.050.12.280.090.040.040.092.590.09FN1.325.182.320.226.871.196.642.550.217.17Accuracy99.9299.999.8299.5999.7999.9299.9099.8199.5799.78Precision98.2994.1697.6599.7794.7698.3794.9697.7599.7494.77Recall98.6894.8297.6899.7893.1398.8193.3697.4599.7992.83F-score98.4894.4897.6699.7793.9398.5994.1597.6099.7693.79KNNTN99.5999.8199.3880.1699.9899.6399.8199.3780.6099.98FP0.410.190.6219.840.020.370.190.6319.400.02FN16.1332.1127.180.640.5516.2428.7427.270.5938.31Accuracy99.1799.5398.3497.6299.2699.2199.5598.3397.6799.30Precision84.8476.4682.5598.0197.786.2676.5282.3298.0598.27Recall83.8767.8972.8299.459.4583.7671.2672.7399.4161.69F-score84.3471.8877.3698.773.9184.9973.8077.2398.7275.80RFTN99.9599.9399.9398.2899.9699.9599.9499.9598.2899.96FP0.050.070.071.720.040.050.060.051.720.04FN0.910.961.890.177.040.600.722.030.156.99Accuracy99.9399.9299.8699.6999.8499.9399.9499.8799.7199.84Precision98.1692.8198.2499.8297.8498.1193.9498.6899.8297.66Recall99.0999.0498.1199.8392.9699.4099.2897.9799.8593.01F-score98.6295.8298.1799.8395.3398.7596.5498.3299.8495.28NBTN99.4891.6296.0456.0199.9599.5091.4995.9557.4299.96FP0.528.383.9643.990.050.508.514.0542.580.04FN63.8625.0970.412.4840.9361.8226.4570.8712.5840.60Accuracy97.7891.4793.4584.6199.2397.8591.3393.3484.6599.24Precision65.477.3923.2695.1495.8367.687.1622.5595.2896.20Recall36.1474.9129.687.5259.0738.1873.5529.1387.4259.40F-score46.5413.4426.0491.1773.0848.8213.0525.4291.1873.45Table 12
The performance of deep learning for WSN dataset using LSTM and GRU with all features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingLSTM with one layerTN99.9999.9810099.9910098.7199.9099.3592.9099.92FP0.010.0200.0101.290.100.657.100.08FN00.050.263.1923.337.056.6443.770.6310.66Accuracy99.9999.9810099.9810098.5599.8497.6798.7799.73Precision10099.9210096.769566.4788.9577.9399.2895.25Recall10099.9599.7496.8176.6792.9593.3656.2399.3789.34F-score10099.9399.8796.7583.6777.5191.1065.3399.3292.20LSTM with two layerTN98.6599.8699.4191.7399.8998.6699.8699.5093.7399.89FP1.350.140.598.270.111.340.140.506.270.11FN8.527.3647.460.5912.218.323.5043.660.5011.20Accuracy98.4699.7997.5898.799.6798.4799.8397.8298.9699.69Precision65.1585.1978.3999.1693.365.3186.1982.0199.3693.53Recall91.4892.6452.5499.4187.7991.6896.5056.3499.5088.80F-score76.0788.7462.8799.2990.4476.2891.0566.8099.4391.10GRU with one layerTN98.6799.8799.391.8299.8898.7899.8999.2493.2999.93FP1.330.130.78.180.121.220.110.766.710.07FN9.619.4246.840.6511.8912.866.7640.940.5710.66Accuracy98.4599.7997.598.6699.6898.4799.8397.6898.8699.75Precision65.3286.575.6799.1793.1766.2788.4375.9399.3296.11Recall90.3990.5853.1699.3588.1187.1493.2459.0699.4389.34F-score75.788.4762.2399.2690.5675.2990.7766.4499.3792.60GRU with two layerTN98.6399.8599.4694.0599.998.7999.8799.3196.4599.91FP1.370.150.545.950.11.210.130.693.550.09FN8.083.7543.340.5611.3115.212.7834.060.4810.36Accuracy98.4599.8297.7998.9599.798.4199.8598.0199.2399.73Precision65.0285.5280.999.494.1665.8886.9379.4899.6494.96Recall91.9296.2556.6699.4488.6984.7997.2265.9499.5289.64F-score76.1190.5466.4399.4291.3474.1591.7972.0899.5892.22Table 13
The performance of deep learning for WSN dataset using LSTM and GRU with selected features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingLSTM with one layerTN98.5999.9199.489699.9398.5099.9299.7396.6199.99FP1.410.090.5240.071.500.080.273.390.01FN6.828.539.190.479.91.635.1940.120.339.22Accuracy98.4599.8497.9899.2199.7698.5099.8898.1899.3999.83Precision64.8490.683.3799.5996.0864.4291.4989.9299.6699.47Recall93.1891.560.8199.5390.198.3794.8159.8899.6790.78F-score76.291.0269.9899.5692.9877.8593.1271.8999.6694.93LSTM with two layerTN98.4199.999.1794.6299.9298.4899.9199.2594.5199.88FP1.590.10.835.380.081.520.090.755.490.12FN3.313.342.910.8321.435.104.1142.500.8019.88Accuracy98.3799.7997.5398.7599.5498.3899.8797.6298.7699.53Precision62.6889.5973.9599.4594.8563.2590.4375.6699.4492.62Recall96.786.757.0999.1778.5794.9095.8957.5099.2080.12F-score76.0487.6864.3799.3185.8575.9193.0865.3499.3285.92GRU with one layerTN99.0899.9199.397.8599.9998.6299.9399.7897.9199.99FP0.920.090.72.150.011.380.070.222.090.01FN21.713.2623.880.217.733.426.2834.230.227.89Accuracy98.5299.8898.499.6199.8598.5799.8798.4699.6099.85Precision72.6990.3683.7299.7899.2765.8791.9492.4999.7999.61Recall78.2996.7476.1299.7992.2796.5893.7265.7799.7892.11F-score72.6293.4378.5899.7895.6478.3292.8276.8799.7895.7GRU with two layerTN98.5399.9399.2589.199.8198.6599.9199.4994.1199.82FP1.470.070.7510.90.191.350.090.515.890.18FN5.8539.2653.040.5419.997.449.7842.090.4913.73Accuracy98.4199.5997.2198.599.4698.4999.8397.8799.0199.58Precision63.8788.5872.0198.988.1665.4490.3382.0699.4089.44Recall94.1560.7446.9699.4680.0192.5690.2257.9199.5186.27F-score76.0979.7356.7899.1883.8576.6790.2767.9099.4687.83


#### 4.2.1. Regular Machine Learning Using All Features

(1) Cross-Validation Results. Table 10 shows the machine learning models’ performance using the unseen testing WSN-DS dataset. For the normal class, RF is the highest performance model (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score 98.96%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.93%, 99.46%, and 98.20%, respectively. For the Grayhole class, DT is the highest performance model (accuracy of 99.95%, precision of 97.32%, recall of 96.89%, and F-score 97.1%). At the same time, NB is the worst performing model (accuracy of 92.95%, precision of 8.51%, recall of 80.00%, and F-score 15.38%). Similar to Blackhole class, RF is the highest performance model (accuracy of 99.87%, precision of 98.3%, recall of 98.47%, and F-score 98.39%). Regarding scheduling and flooding classes, RF obtained the highest performance by accuracy of 99.74% and 99.89%, respectively. However, NB is the worst performing model for both classes, including accuracy of 84.10% for scheduling and 90.15% for flooding. Yet, the NB model using Scheduling classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 84.65%.(2) Testing Results. As shown in the results, for the normal class, the RF model has achieved the highest performances among other models (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score 98.96%). However, the NB model has recorded the worst performances among other models (accuracy of 98.20%, precision of 97.07%, recall of 34.69%, and F-score 51.11%). For the grayhole class, DT and RF have achieved the highest performances among other models (accuracy of 99.95%). However, the NB model has recorded the worst performances among other models (accuracy of 92.95%, precision of 8.51%, recall of 80.0015.38%, and F-score 15.38%). Like the blackhole class, the RF model has achieved the highest performances among other models (accuracy of 99.87%, precision of 98.3%, a recall of 98.47%, and F-score of 98.39%). However, the NB model has recorded the worst performances among other models (accuracy of 94.40%, precision of 34.91%, recall of 47.76%, and F-score of 40.33%). Regarding scheduling class, the RF model has achieved the highest performances among other models (accuracy of 99.74%, precision of 99.84%, recall of 99.88%, and F-score of 99.86%). However, the NB model has recorded the worst performances among other models (accuracy of 84.10%, precision of 99.89%, recall of 82.58%, and F-score of 90.41%). Flooding class like the other classes, the RF model, has achieved the highest performances among other models (accuracy of 99.89%, precision of 99.78%, recall of 93.93%, and F-score of 96.77%). However, the NB model has recorded the worst performances among other models (accuracy of 90.15%, precision of 13.37%, recall of 84.01%, and F-score of 23.07%). Based on these results, RF and DT models for the grayhole class are the best performing models with respect to other models, while the NB model for scheduling class is the worst performing model.


#### 4.2.2. Regular Machine Learning Using Selected Features

In this section, the machine learning performance results of applying feature selection using WSN-DS dataset are presented.(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the WSN-DS dataset with selected features, as shown in Table 11. As shown in the normal class results, RF has achieved the highest performances among other models and other classes (accuracy of 99.93%, precision of 98.16%, recall of 99.09%, and F-score of 98.62%). The DT model has achieved the second one, KNN is the third one, and the fourth one is NB. For the grayhole class, RF has achieved the highest performances among other models (accuracy of 99.92%, precision of 92.81%, recall of 99.04%, and F-score of 95.82%). In contrast, NB has done the worst performances (accuracy of 91.47%, precision of 7.39%, recall of 74.91%, and F-score of 13.44%). Like blackhole class, RF has achieved the highest performances among other models (accuracy of 99.86%, precision of 98.24%, recall of 98.11%, and F-score of 98.17%). In contrast, NB has done the worst performances (accuracy of 93.45%, precision of 23.26%, recall of 29.6%, and F-score of 26.04%). Regarding scheduling class, RF has achieved the highest performances among other models (accuracy of 99.69%, precision of 99.82%, recall of 99.83%, and F-score of 99.83%). In contrast, NB has done the worst performances (accuracy of 84.61%, precision of 95.14%, recall of 87.52%, and F-score of 91.17%). Flooding class like the other classes, RF has achieved the highest performances among other models (accuracy of 99.84%, precision of 97.84%, recall of 92.96%, and F-score of 95.33%). In contrast, NB has done the worst performances (accuracy of 99.23%, precision of 95.83%, recall of 59.07%, and F-score of 73.08%). Based on these results, the RF model using normal class is the best performing model concerning other models, while NB using Scheduling class is the worst performing model.(2) Testing Results. Table 10 shows the performance of the machine learning models using the unseen testing WSN-DS dataset. For the normal class, RF is the highest performance model (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score of 98.96%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.93%, 99.46%, and 98.20%, respectively. For the grayhole class, DT is the highest performance model (accuracy of 99.95%, precision of 97.32%, recall of 96.89%, and F-score of 97.1%). At the same time, NB is the worst performing model (accuracy of 92.95%, precision of 8.51%, recall of 80.00%, and F-score of 15.38%). Similar to blackhole class, RF is the highest performance model (accuracy of 99.87%, precision of 98.3%, recall of 98.47%, and F-score of 98.39%). Regarding scheduling and flooding classes, RF obtained the highest performance by accuracy of 99.74% and 99.89%, respectively. However, NB is the worst performing model for both classes, including accuracy of 84.10% for scheduling and 90.15% for flooding. Yet, the NB model using scheduling classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 84.65%.


#### 4.2.3. Deep Learning Using All Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four deep learning models (LSTM and GRU, using one and two layers) over the WSN-DS dataset with all features, as shown in Table 12. As shown in the results, for the normal class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 100%, recall of 100%, and F-score of 100%). LSTM using two layers’ model has achieved the second one, and GRU with one layer and two layers’ models have almost similar performances which achieved the third one. For the grayhole class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.98%, precision of 99.92%, recall of 99.95%, and F-score of 99.93%). In contrast, GRU with two layers has done the second one, and LSTM using one layer and GRU with two layers has done similar performances ranked as a third one. Like blackhole class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 100%, precision of 100%, recall of 99.74%, and F-score of 99.87%). In contrast, GRU with one layer has done the worst performances (accuracy of 97.5%, precision of 75.67%, recall of 53.16%, and F-score of 62.23%). Regarding scheduling class, LSTM using one layer has achieved the highest performances among other models (accuracy of 99.98%, precision of 96.76%, recall of 96.81%, and F-score of 96.75%). Flooding class like the other classes, LSTM using one layer has achieved the highest performances among other models (accuracy of 100% and precision of 95%), while other models include LSTM using two layers, and GRU using one layer and two layers has achieved approximated performances in terms of accuracy such as 99.67%, 99.68%, and 99.7%, respectively. Based on these results, LSTM using one layer model for blackhole and flooding classes is the best performing model with respect to other models, while GRU using one and two layers for normal class is the worst performing model.(2) Testing Results. Table 12 shows the performance of the deep learning models using the unseen testing WSN-DS dataset. As shown in the results, for the normal class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.55%, precision of 66.47%, recall of 92.95%, and F-score of 77.51%). LSTM using two layers and GRU has one layer models have achieved the second one, and GRU with two layers has achieved the third one. For the grayhole class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 99.85%, precision of 86.93%, recall of 97.22%, and F-score of 91.79%). LSTM using one layer has performed the second one, LSTM using two layers and GRU with one layer have done the third one, and LSTM using one layer and GRU with two layers are ranked as a third one. Similar to blackhole class, GRU using two layers model has achieved the highest performances among other models and other classes (accuracy of 98.01%, precision of 79.48%, recall of 65.94%, and F-score 72.08%), while LSTM with one layer has done the worst performances (accuracy of 97.67%, precision of 77.93%, recall of 56.23%, and F-score 65.33%). Regarding scheduling class, GRU using two layers has achieved the highest performances among other models (accuracy of 99.23%, precision of 99.64%, recall of 99.52%, and F-score of 99.58%). For flooding class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.75%, precision of 96.11%, recall of 89.34%, and F-score of 92.60%). Based on these results, GRU using two layers’ model for grayhole is the best performing model with respect to other models, while GRU using one layer for blackhole class is the worst performing model.


#### 4.2.4. Deep Learning Using Selected Features

(1) Cross-Validation Results. As shown in the result in Table 13, four deep learning models were over the WSN-DS dataset with selected features, and for the normal class, GRU using one layer model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 98.52%, precision of 72.69%, recall of 78.29%, and F-score of 72.62%). LSTM using one layer, GRU with two layers, and LSTM using two layers have been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the grayhole class, GRU using one layer model has achieved the highest performances among other models (accuracy of 99.88%, precision of 90.36%, recall of 96.74%, and F-score of 93.43%). In contrast, LSTM with one layer, GRU with one layer, and GRU with two layers have recorded the second, third, and fourth models based on their accuracy. Like the blackhole class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.4%, precision of 83.72%, recall of 76.12%, and F-score of 78.58%). In contrast, GRU with two-layer has done the worst performances (accuracy of 97.21%, precision of 72.01%, recall of 46.96%, and F-score of 56.78%).Regarding scheduling class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.61%, precision of 99.78%, recall of 99.79%, and F-score of 99.78%). Flooding class like the other classes, GRU using one layer has achieved the highest performances among other models (accuracy of 99.85%, precision of 99.27%, recall of 92.27%, and F-score of 95.64%). Based on these results, GRU using one layer model for grayhole is the best performing model with respect to other models, while GRU using two layers for the blackhole class is the worst performing model.(2) Testing Results. Table 13 shows the performance of the machine learning models using the unseen testing WSN-DS dataset. As shown in the results, for the normal class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.57%, precision of 65.87%, recall of 96.58%, and F-score of 78.32%). However, LSTM using two layers’ model has recorded the worst performances among other models and other classes (accuracy of 98.38%, precision of 63.25%, recall of 94.90%, and F-score of 75.91%). For the grayhole class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.88%, precision of 91.49%, recall of 94.81%, and F-score of 93.12%). GRU using two layers’ model has recorded the worst performances among other models and other classes (accuracy of 99.83%, precision of 90.33%, recall of 90.22%, and F-score of 90.27%). Like the blackhole class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.46%, precision of 92.49%, recall of 65.77%, and F-score of 76.87%). In contrast, LSTM with two layers has the worst performances (accuracy of 97.62%, precision of 75.66%, recall of 57.50%, and F-score of 65.34%). Regarding the scheduling class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.60%, precision of 99.79%, recall of 99.78%, and F-score 99.78%). In contrast, LSTM with two layers has done the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score 99.32%). Flooding class like the other classes, GRU using one layer model has achieved the highest performances among different models and other classes (accuracy of 99.85%, precision of 99.61%, recall of 92.11%, and F-score of 95.7%). In contrast, LSTM with two layers has the worst performances (accuracy of 99.53%, precision of 92.62%, recall of 80.12%, and F-score of 85.92%). Based on these results, LSTM using one layer model for grayhole is the best performing model with respect to other models, while LSTM using one layer for the blackhole class is the worst performing model.


### 4.3. KDD Dataset

In this section, the results of applying four machine learning models (DT, KNN, RF, and NB) and four deep learning models (LSTM and GRU, using one and two layers), including cross-validation results and testing results, are described. Each machine learning model and deep learning model performance is discussed using full features and selected features to classify five classes of attack types includingDOS, R2L, U2R, Probe, and Normal. All the positive and negative rates results of the cross-validation and testing performances which are used to compute accuracy, precision, recall, and F-score matrices are presented in Tables 14–17.Table 14
The performance of machine learning for KDD dataset using all features.
ModelsEvaluation metricCross-validation performanceTesting performanceDOSNormalProbeR2LU2RDOSNormalProbeR2LU2RDTTNR99.9799.9899.9910010099.9599.9810099.99100FPR0.030.020.01000.050.0200.010FNR00.080.683.0125.8300.070.725.6350Accuracy99.9999.9799.9999.9999.9999.9999.9799.9999.9899.99Precision99.9999.9399.2798.174.1799.9999.8910097.166.67Recall10099.9299.3296.9974.1710099.9399.2894.3750F-score10099.9299.2997.5370.699.9999.9199.6495.7157.14KNNTNR99.6199.9499.9899.9910099.5599.8999.9699.99100.00FPR0.390.060.020.0100.450.110.040.010.00FNR0.010.189.765.651000.040.2912.278.45100.00Accuracy99.9199.9299.999.9899.9999.8999.8599.8599.9799.99Precision99.9199.7197.8296.31099.9099.4795.6795.590Recall99.9999.8290.2494.35099.9699.7187.7391.550.00F-score99.9599.7693.8795.28099.9399.5991.5393.530RFTNR99.9999.98100100100100.099.98100.00100.00100.00FPR0.010.020000.00.020.000.000.00FNR00.020.413.23400.00.010.803.5241.67Accuracy10099.9810099.99100100.099.9899.9999.99100.00Precision10099.999.9799.3693.75100.099.8999.8299.7087.50Recall10099.9899.5996.7760100.099.9999.2096.4858.33F-score10099.9499.7898.0477.8100.099.9499.5198.0670.00NBTNR73.2399.8797.5299.0297.8871.7199.8699.5499.1097.89FPR26.770.132.480.982.1228.290.140.460.902.11FNR3.0740.393.0498.65450.6341.05100.00100.0075.00Accuracy92.4492.7296.7498.7797.8894.1792.6598.6598.8797.88Precision93.93990.30.250.2493.8298.920.000.000.15Recall96.9359.76.961.355599.3758.950.000.0025.00F-score95.2674.485.74.220.696.5273.87000.31Table 15
The performance of machine learning for KDD dataset using selected features.
ModelsEvaluation metricCross-validation performanceTesting performanceDosNormalProbeR2LU2RDOSNormalProbeR2LU2RDTTNR98.7599.9599.9810010098.9199.9599.9799.99100.00FPR1.250.050.02001.090.050.030.010.00FNR0.060.1725.372.450.830.060.1822.762.0575.00Accuracy99.7299.9399.7699.9999.9999.7499.9399.7899.9999.99Precision99.7199.7696.7598.4375.9399.7499.7795.6097.9542.86Recall99.9499.8674.6397.649.1799.9499.8277.2497.9525.00F-score99.8399.884.259857.7899.8499.8085.4597.9531.58KNNTNR98.5599.8799.9799.9910098.7299.8699.9899.99100.00FPR1.450.130.030.0101.280.140.020.010.00FNR0.070.3827.6516.111000.070.3325.0719.94100.00Accuracy99.6799.8399.7399.9599.9999.7099.8399.7699.9499.99Precision99.6699.4195.8996.80.099.7099.3796.4594.790.0Recall99.9399.6272.3583.89099.9399.6774.9380.060.00F-score99.899.5182.4689.810.099.8199.5284.3486.800.0RFTNR98.7699.9499.9810010098.9199.9599.97100.00100.00FPR1.240.060.02001.090.050.030.000.00FNR0.060.1425.293.08400.060.1322.313.8158.33Accuracy99.7299.9399.7699.9910099.7499.9499.7899.9999.99Precision99.7199.7696.6699.7487.0499.7499.7796.1599.3971.43Recall99.9499.8674.7196.926099.9499.8777.6996.1941.67F-score99.8399.884.2698.371.8599.8499.8285.9497.7652.63NBTNR21.699.7597.6599.4979.4721.2799.7299.7299.5277.36FPR78.40.252.350.5120.5378.730.280.280.4822.64FNR24.797.3592.9798.6420.8324.9096.72100.00100.008.33Accuracy65.1382.4696.8799.2479.4764.8782.4898.8799.2777.36Precision80.4466.470.290.480.0980.2771.770.000.000.04Recall75.32.657.031.3679.1775.103.280.000.0091.67F-score77.785.085.613.560.1977.606.27000.07Table 16
The performance of deep learning for KDD dataset using LSTM and GRU with all features.
ModelEvaluation metricCross-validation performanceTesting performanceDOSNormalProbeR2LU2RDOSNormalProbeR2LU2RLSTM with one layerTNR98.799.8799.2491.8399.8899.9899.96100.0099.99100.00FPR1.30.130.768.170.120.020.040.000.010.00FNR10.429.6446.160.6811.670.010.061.247.6266.67Accuracy98.4699.7997.4798.6399.6899.9999.9599.9999.9799.99Precision65.6186.1674.4899.1793.07100.0099.8099.5597.2266.67Recall89.5890.3653.8499.3288.3399.9999.9498.7692.3833.33F-score75.688.262.2899.2490.62100.0099.8799.1594.7444.44LSTM with two layerTNR99.8999.7510099.9510099.9299.9399.9999.96100.00FPR0.110.2500.0500.080.070.010.040.00FNR0.180.352.6615.571000.010.292.2210.85100.00Accuracy99.8399.7399.9799.9199.9999.9899.8999.9899.9399.99Precision99.9798.8599.5882.2099.9899.7099.3784.920Recall99.8299.6597.3484.43099.9999.7197.7889.150.00F-score99.999.2598.4483.27099.9999.7098.5786.980GRU with one layerTNR99.8899.5610099.9610099.9299.90100.0099.97100.00FPR0.120.4400.0400.080.100.000.030.00FNR0.370.323.0714.281000.040.252.9311.73100.00Accuracy99.6799.5899.9799.9299.9999.9599.8799.9799.9399.99Precision99.979899.4684.57099.9899.5399.5486.740Recall99.6399.6896.9385.72099.9699.7597.0788.270.00F-score99.898.8398.1785.05099.9799.6498.2987.500GRU with two layerTNR99.8999.5399.9999.9610099.9699.87100.0099.97100.00FPR0.110.470.010.0400.040.130.000.030.00FNR0.380.282.6223.671000.050.192.6714.96100.00Accuracy99.6799.5699.9799.999.9999.9599.8699.9799.9399.99Precision99.9897.8799.286.37099.9999.4399.6487.350Recall99.6299.7297.3876.33099.9599.8197.3385.040.00F-score99.898.7898.2876.73099.9799.6298.4786.180Table 17
The performance of deep learning for KDD dataset using LSTM and GRU with selected features.
ModelEvaluation metricCross-validation performanceTesting performanceDOSNormalProbeR2LU2RDOSNormalProbeR2LU2RLSTM with one layerTNR66.9698.7510099.9910078.0698.50100.0099.99100.00FPR33.041.2500.01021.941.500.000.010.00FNR0.9530.6310079.181001.0619.57100.0077.13100.00Accuracy92.9893.5199.1399.7999.9994.9895.2799.1599.7999.99Precision92.9192.35084.040.095.0692.090.082.110.0Recall99.0569.37020.82098.9480.430.0022.870.00F-score95.8477.590.039.480.096.9685.870.035.780.0LSTM with two layerTNR81.5398.3799.9910010085.8398.37100.0099.99100.00FPR18.471.630.010014.171.630.000.010.00FNR1.2415.9387.6994.941001.4011.5076.0976.83100.00Accuracy95.4995.8299.2299.7699.9996.1796.6099.3599.7999.99Precision95.8291.7884.5891.370.096.7492.1998.1886.810.0Recall98.7684.0712.315.06098.6088.5023.9123.170.00F-score97.2687.7133.9439.520.097.6690.3138.4636.570.0GRU with one layerTNR78.7399.2210010010079.0099.19100.00100.00100.00FPR21.270.7800021.000.810.000.000.00FN0.3618.261001001000.3618.15100.00100.00100.00Accuracy95.6896.1199.1399.7599.9995.7296.0999.1599.7499.99Precision95.2595.770.00.00.095.2995.660.00.00.0Recall99.6481.7400099.6481.850.000.000.00F-score97.488.20.00.00.097.4288.220.00.00.0GRU with two layerTNR82.998.9499.9999.9810083.2599.3499.9899.99100.00FPR17.11.060.010.02016.750.660.020.010.00FNR0.7714.486.8373.341000.4614.1176.0976.54100.00Accuracy96.1496.5699.2499.899.9996.4596.9399.3499.7999.99Precision96.1394.6291.6780.40.096.2096.5993.0883.330.0Recall99.2385.613.1726.66099.5485.8923.9123.460.00F-score97.6589.8835.2839.920.097.8490.9238.0536.610.0


#### 4.3.1. Regular Machine Learning Using All Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the KDD dataset with all features, as shown in Table 14. As shown in the results, for the Dos class, RF has achieved the highest performances among other models and other classes (accuracy of 100%, precision of 100%, recall of 100%, and F-score of 100%). The DT model has achieved the second one and KNN is the third one. NB has reached the lowest performances (accuracy of 92.44%, precision of 93.93%, recall of 96.93%, and F-score 95.26%). For the normal class, RF has achieved the highest performances among other models (accuracy of 99.98%, precision of 92.9%, recall of 99.98%, and F-score of 95.94%). In contrast, NB has the worst performances (accuracy of 92.72%, precision of 99%, recall of 59.7%, and F-score 74.48%). Like the probe class, RF has achieved the highest performances among other models (accuracy of 100%, precision of 99.97%, recall of 99.59%, and F-score of 99.78%). In contrast, NB has the worst performances (accuracy of 96.74%, precision of 0.3%, recall of 6.96%, and F-score of 5.7%). Regarding R2l class, RF has achieved the highest performances among other models (accuracy of 99.99%, precision of 99.36%, recall of 96.77%, and F-score of 98.04%). In contrast, NB has the worst performances (accuracy of 98.77%, precision of 0.25%, recall of 1.35%, and F-score of 4.22%). U2r class classes, RF has achieved the highest performance (accuracy of 100%, precision of 93.75%, and F-score of 77.8%), while DT has achieved the highest recall of 96.99%. KNN and NB have the worst performances. Based on these results, the RF model using the DoS class is the best performing model with respect to other models.(2) Testing Results. Table 14 shows the performance of the machine learning models using the unseen testing KDD dataset. For the RF model, DOS class has achieved the highest accuracy among other models and classes (accuracy of 100%, precision of 100%, recall of 100%, and F-score of 100%). However, NB has the DOS class’s worst performances (accuracy of 94.17%, precision of 93.82%, recall of 99.37%, and F-score of 96.52%). For the normal class, RF is the highest performance model (accuracy of 99.98%, precision of 99.89%, recall of 99.99%, and F-score of 98.94%). DT, KNN, and NB models have achieved the second, third, and fourth ranks based on accuracy over unseen data by 99.97%, 99.85%, and 92.65%, respectively. Similar to the probe class, DT is the highest performance model (accuracy of 99.99%, precision of 100%, recall of 99.28%, and F-score of 96.64%). RF, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.99%, 99.85%, and 98.65%, respectively. Regarding R2l and U2r classes, RF obtained the highest performance, while NB is the worst performing model for both classes. However, the NB model using normal classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 92.65%.


#### 4.3.2. Regular Machine Learning Using Selected Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the KDD dataset with all features, as shown in Table 15. As shown in the results, for the DOS class, RF and DT have achieved the highest performances among other models and other classes (accuracy of 99.72%, precision of 99.71%, recall of 99.94%, and F-score of 99.83%). The KNN model has achieved the second one. NB has achieved the lowest performances (accuracy of 65.13%, precision of 80.44%, recall of 75.3%, and F-score of 77.78%). For the normal class, RF and DT have achieved the highest performances among other models (accuracy of 99.93%, precision of 99.76%, recall of 99.86%, and F-score of 99.8%), while NB has the worst performances (accuracy of 82.46%, precision of 66.47%, recall of 2.65%, and F-score of 5.08%). The probe class, RF has achieved the highest performances among other models (accuracy of 99.99%, precision of 99.74%, and F-score of 98.3%), while DT has achieved the highest recall of 97.6%. NB has the worst performances (accuracy of 96.87%, precision of 0.29%, recall of 7.03%, and F-score of 5.61%). Regarding R2l class, RF has achieved the highest performances among other models (accuracy of 100%, precision of 87.04%, recall of 60%, and F-score of 71.85%), while NB has the worst performances (accuracy of 99.24%, precision of 0.48%, recall of 1.36%, and F-score 3.56%). U2R classes, RF and DT, have achieved similar the highest performance. NB has the worst performances (accuracy of 79.47%, precision of 0.09%, recall of 79.17, and F-score of 0.19). Based on these results, RF and DT models for each class have the best performing model with respect to other models, while NB has the worst performances.(2) Testing Results. Table 15 shows the performance of the machine learning models using the unseen testing KDD dataset. For the RF and DT model, DOS class has achieved the highest accuracy among other models and classes (accuracy of 99.74%, precision of 99.74%, recall of 99.94%, and F-score of 99.84%). However, NB has the DOS class’s worst performances (accuracy of 64.87%, precision of 80.27%, recall of 75.10%, and F-score of 77.60%). For the normal class, DT and RF are the highest performance model (accuracy of 99.93%, precision of 99.77%, recall of 99.82%, and F-score of 99.80%). KNN and NB models have achieved the second and third ranks based on accuracy over unseen data by 99.83% and 82.48%, respectively. Similar to the probe class, RF is the highest performance model (accuracy of 99.78%, precision of 96.15%, recall of 77.69%, and F-score of 85.94%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.78%, 99.76%, and 98.87%, respectively. Regarding R2L and U2R classes, RF obtained the highest performance, while NB is the worst performing model for both classes.


#### 4.3.3. Deep Learning Using All Features

(1) Cross-Validation Results. As shown in the result in Table 16, four deep learning models were over the KDD dataset with selected features; for the DOS class, LSTM using two layers’ model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 99.83%, precision of 99.97%, recall of 99.82%, and F-score of 99.9%). LSTM using one layer, GRU with one layer and two layers, and LSTM using one layer has been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the normal class, LSTM using two layers’ model has achieved the highest performances among other models (accuracy of 99.73%, precision of 98.85%, recall of 99.65%, and F-score of 99.25%). In contrast, LSTM with one layer has achieved the lowest performance (accuracy of 99.79%, precision of 86.16%, recall of 90.36%, and F-score of 88.2%). GRU with one layer and GRU with two layers have recorded the second, third, and accuracy. Like the probe class, LSTM using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.97%, precision of 99.58%, recall of 97.34%, and F-score of 98.44%). In contrast, LSTM with one layer has the worst performances (accuracy of 97.47%, precision of 74.48%, recall of 53.84%, and F-score of 62.28%). Regarding R2l class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.92%, precision of 84.57%, recall of 85.72%, and F-score of 85.05%). U2R class like the other classes, GRU using one layer has achieved the highest performances among other models accuracy of 99.68%, precision of 93.07%, recall of 88.33%, and F-score of 90.62%). Based on these results, LSTM using two layers’ model for DOS is the best performing model with respect to other models.(2) Testing Results. As shown in the result in Table 16, four deep learning models were over the KDD dataset with selected features; for the DOS class, LSTM using two layers’ model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 99.83%, precision of 99.97%, recall of 99.82%, and F-score of 99.9%). LSTM using one layer, GRU with one layer and two layers, and LSTM using one layer has been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the normal class, LSTM using two layers’ model has achieved the highest performances among other models (accuracy of 99.73%, precision of 98.85%, recall of 99.65%, and F-score of 99.25%). In contrast, LSTM with one layer has achieved the lowest performance accuracy of 99.79%, precision of 86.16%, recall of 90.36% and F-score of 88.2%). GRU with one layer and GRU with two layers have recorded the second and third and accuracy. Like the probe class, LSTM using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.97%, precision of 99.58%, recall of 97.34%, and F-score of 98.44%). Table 16 shows the performance of the deep learning models using the unseen testing KDD dataset. As shown in the results, for the DOS class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 100%, recall of 99.99%, and F-score of 100%). LSTM using two layers’ model and GRU models have similar performance. For the normal class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.95%, precision of 99.80%, recall of 99.94%, and F-score of 99.87%). LSTM with two layers and GRU using one layer and two layers model have recorded the similar performances. Like the probe class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 99.55%, recall of 98.76%, and F-score of 99.15%). Regarding the scheduling class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.60%, precision of 99.79%, recall of 99.78% and F-score99.78%). In contrast, LSTM with two layers has done the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score of 99.32%). Flooding class like the other classes, GRU using one layer model has achieved the highest performances among different models and other classes (accuracy of 99.85%, precision of 99.61%, recall of 92.11%, and F-score of 95.7%). In contrast, LSTM with two layers has the worst performances (accuracy of 99.53%, precision of 92.62%, recall of 80.12%, and F-score of 85.92%). Based on these results, LSTM using one layer model for grayhole is the best performing model for other models, while LSTM using one layer for the blackhole class is the worst performing model.


#### 4.3.4. Deep Learning Using Selected Features

(1) Cross-Validation Results. As shown in the result, in Table 17, four deep learning models were over the KDD dataset with selected features; for the DOS class, GRU using two layers, model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 96.14%, precision of 96.13%, recall of 99.23%, and F-score of 97.65%). LSTM using one layer model has achieved the lowest performances based on its accuracy among other models and other classes (accuracy of 92.98%, precision of 92.91%, recall of 99.05%, and F-score of 95.84%). For the normal class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 96.56%, precision of 94.62%, recall of 85.6%, and F-score 89.88%). In contrast, LSTM with one layer has reached the lowest performance accuracy of 93.51%, precision of 92.35%, recall of 69.37%, and F-score of 77.59%). Similar to the probe class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.24%, precision of 99.58%, recall of 13.17%, and F-score of 35.28%). In comparison, LSTM with one and two layers and GRU with one layer have registered similar performance. Regarding R2l class, GRU using two layers has achieved the highest performances among other models (accuracy of 99.8%, precision of 80.4%, recall of 26.66%, and F-score of 39.92%). U2R class is like the other classes; all deep learning models have recorded the same performance (accuracy of 99.99%, precision of 0%, recall of 0%, and F-score 0%). Based on these results, all models for U2R are the worst performance concerning other models.(2) Testing Results. Table 17 shows the performance of the deep learning models using the unseen testing KDD dataset. As shown in the results, for the DOS class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 96.45%, precision of 96.20%, recall of 99.54%, and F-score of 97.84%). In contrast, LSTM with one layer has registered the lowest performance (accuracy of 94.98%, precision of 95.06%, recall of 98.94%, and F-score of 96.96%). For the normal class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 96.93%, precision of 96.59%, recall of 85.89%, and F-score of 90.92%). LSTM with one layer has recorded the worst performances (accuracy of 95.27%, precision of 92.09%, recall of 80.43%, and F-score of 85.87%). Like the probe class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.24%, precision of 91.67%, recall of 23.91%, and F-score of 38.05%). Regarding R2L class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.79%, precision of 83.33%, recall of 23.46%, and F-score of 36.61%). In comparison, LSTM with two layers has the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score of 99.32%). For U2R class, all models have achieved the worst performance. Based on these results, GRU using two layers’ model have registered the best performance.


## 4.1. Experiment Setup

The machine learning models and deep learning models which are applied on the collected datasets has been developed in Python3 using Anaconda Python 3. The experiments have been conducted using a laptop with a specification of 20 GB of RAM, 7 cores, and 100 GB disk. The machine learning models and deep learning models have been trained using 70% dataset, while the rest of 30% of dataset has been used for testing. The machine learning models have been implemented using Sklearn library, while the deep learning models have been implemented using Tensorflow and Keras packages.


## 4.2. WSN-DS Dataset

This section presents the results of applying machine learning models (DT, KNN, RF, and NB) and four deep learning models (LSTM and GRU, using one and two layers), and cross-validation results and testing results are described. Each machine learning model and deep learning model performance is discussed using full features and selected features to classify five classes of attack types, includingNormal, Grayhole, Blackhole, Scheduling, and Flooding. All the positive and negative rates results of the cross-validation and testing performances used to compute accuracy, precision, recall, and F-score matrices are presented in Tables 10–13.Table 10
The performance of machine learning for WSN dataset using all features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingDTTN99.9799.9699.9297.7499.8999.9699.9899.998.2399.89FP0.030.040.082.260.110.040.020.11.770.11FN0.944.731.80.217.11.183.111.440.236.07Accuracy99.9599.9199.8699.699.7799.9399.9599.8599.6399.78Precision98.9395.2498.1299.7794.1198.5697.3297.699.8293.74Recall99.0695.2798.299.7992.998.8296.8998.5699.7793.93F-score98.9995.2498.1699.7893.598.6997.198.0899.7993.83KNNTN99.7199.8599.5684.2599.8999.7299.999.5784.1499.89FP0.290.150.4415.750.110.280.10.4315.860.11FN10.3525.3620.580.5335.259.8222.6721.010.4936.23Accuracy99.4499.6398.7898.0699.2799.4699.7298.7598.0999.26Precision89.4681.5788.0298.4191.6889.9585.7188.3598.491.57Recall89.6574.6479.4299.4764.7590.1877.3378.9999.5163.77F-score89.5577.9483.4898.9475.990.0781.3183.4198.9675.18RFTN99.9699.9499.9598.2699.9999.9699.9699.9398.42100FP0.040.060.051.740.010.040.040.071.580FN0.461.361.420.127.230.520.891.530.126.07Accuracy99.9599.9399.8999.7399.8699.9499.9599.8799.7499.89Precision98.669498.6799.8299.5298.4595.398.399.8499.78Recall99.5498.6498.5899.8892.7799.4899.1198.4799.8893.93F-score99.0996.2698.6399.8596.0298.9697.1798.3999.8696.77NBTN99.9793.0696.498.8190.5699.9793.0596.3299.0890.26FP0.036.943.61.199.440.036.953.680.929.74FN65.6918.5753.2116.9918.3165.3120.0052.2417.4215.99Accuracy98.2192.9694.4784.4790.498.2092.9594.4084.1090.15Precision97.149.4834.5399.8513.597.078.5134.9199.8913.37Recall34.3181.4346.7983.0181.6934.6980.0047.7682.5884.01F-score50.6716.9839.7290.6523.1751.1115.3840.3390.4123.07Table 11
The performance of machine learning for WSN dataset using selected features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingDTTN99.9599.9599.997.7299.9199.9699.9699.9197.4199.91FP0.050.050.12.280.090.040.040.092.590.09FN1.325.182.320.226.871.196.642.550.217.17Accuracy99.9299.999.8299.5999.7999.9299.9099.8199.5799.78Precision98.2994.1697.6599.7794.7698.3794.9697.7599.7494.77Recall98.6894.8297.6899.7893.1398.8193.3697.4599.7992.83F-score98.4894.4897.6699.7793.9398.5994.1597.6099.7693.79KNNTN99.5999.8199.3880.1699.9899.6399.8199.3780.6099.98FP0.410.190.6219.840.020.370.190.6319.400.02FN16.1332.1127.180.640.5516.2428.7427.270.5938.31Accuracy99.1799.5398.3497.6299.2699.2199.5598.3397.6799.30Precision84.8476.4682.5598.0197.786.2676.5282.3298.0598.27Recall83.8767.8972.8299.459.4583.7671.2672.7399.4161.69F-score84.3471.8877.3698.773.9184.9973.8077.2398.7275.80RFTN99.9599.9399.9398.2899.9699.9599.9499.9598.2899.96FP0.050.070.071.720.040.050.060.051.720.04FN0.910.961.890.177.040.600.722.030.156.99Accuracy99.9399.9299.8699.6999.8499.9399.9499.8799.7199.84Precision98.1692.8198.2499.8297.8498.1193.9498.6899.8297.66Recall99.0999.0498.1199.8392.9699.4099.2897.9799.8593.01F-score98.6295.8298.1799.8395.3398.7596.5498.3299.8495.28NBTN99.4891.6296.0456.0199.9599.5091.4995.9557.4299.96FP0.528.383.9643.990.050.508.514.0542.580.04FN63.8625.0970.412.4840.9361.8226.4570.8712.5840.60Accuracy97.7891.4793.4584.6199.2397.8591.3393.3484.6599.24Precision65.477.3923.2695.1495.8367.687.1622.5595.2896.20Recall36.1474.9129.687.5259.0738.1873.5529.1387.4259.40F-score46.5413.4426.0491.1773.0848.8213.0525.4291.1873.45Table 12
The performance of deep learning for WSN dataset using LSTM and GRU with all features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingLSTM with one layerTN99.9999.9810099.9910098.7199.9099.3592.9099.92FP0.010.0200.0101.290.100.657.100.08FN00.050.263.1923.337.056.6443.770.6310.66Accuracy99.9999.9810099.9810098.5599.8497.6798.7799.73Precision10099.9210096.769566.4788.9577.9399.2895.25Recall10099.9599.7496.8176.6792.9593.3656.2399.3789.34F-score10099.9399.8796.7583.6777.5191.1065.3399.3292.20LSTM with two layerTN98.6599.8699.4191.7399.8998.6699.8699.5093.7399.89FP1.350.140.598.270.111.340.140.506.270.11FN8.527.3647.460.5912.218.323.5043.660.5011.20Accuracy98.4699.7997.5898.799.6798.4799.8397.8298.9699.69Precision65.1585.1978.3999.1693.365.3186.1982.0199.3693.53Recall91.4892.6452.5499.4187.7991.6896.5056.3499.5088.80F-score76.0788.7462.8799.2990.4476.2891.0566.8099.4391.10GRU with one layerTN98.6799.8799.391.8299.8898.7899.8999.2493.2999.93FP1.330.130.78.180.121.220.110.766.710.07FN9.619.4246.840.6511.8912.866.7640.940.5710.66Accuracy98.4599.7997.598.6699.6898.4799.8397.6898.8699.75Precision65.3286.575.6799.1793.1766.2788.4375.9399.3296.11Recall90.3990.5853.1699.3588.1187.1493.2459.0699.4389.34F-score75.788.4762.2399.2690.5675.2990.7766.4499.3792.60GRU with two layerTN98.6399.8599.4694.0599.998.7999.8799.3196.4599.91FP1.370.150.545.950.11.210.130.693.550.09FN8.083.7543.340.5611.3115.212.7834.060.4810.36Accuracy98.4599.8297.7998.9599.798.4199.8598.0199.2399.73Precision65.0285.5280.999.494.1665.8886.9379.4899.6494.96Recall91.9296.2556.6699.4488.6984.7997.2265.9499.5289.64F-score76.1190.5466.4399.4291.3474.1591.7972.0899.5892.22Table 13
The performance of deep learning for WSN dataset using LSTM and GRU with selected features.
ModelEvaluation metricCross-validation performanceTesting performanceNormalGrayholeBlackholeSchedulingFloodingNormalGrayholeBlackholeSchedulingFloodingLSTM with one layerTN98.5999.9199.489699.9398.5099.9299.7396.6199.99FP1.410.090.5240.071.500.080.273.390.01FN6.828.539.190.479.91.635.1940.120.339.22Accuracy98.4599.8497.9899.2199.7698.5099.8898.1899.3999.83Precision64.8490.683.3799.5996.0864.4291.4989.9299.6699.47Recall93.1891.560.8199.5390.198.3794.8159.8899.6790.78F-score76.291.0269.9899.5692.9877.8593.1271.8999.6694.93LSTM with two layerTN98.4199.999.1794.6299.9298.4899.9199.2594.5199.88FP1.590.10.835.380.081.520.090.755.490.12FN3.313.342.910.8321.435.104.1142.500.8019.88Accuracy98.3799.7997.5398.7599.5498.3899.8797.6298.7699.53Precision62.6889.5973.9599.4594.8563.2590.4375.6699.4492.62Recall96.786.757.0999.1778.5794.9095.8957.5099.2080.12F-score76.0487.6864.3799.3185.8575.9193.0865.3499.3285.92GRU with one layerTN99.0899.9199.397.8599.9998.6299.9399.7897.9199.99FP0.920.090.72.150.011.380.070.222.090.01FN21.713.2623.880.217.733.426.2834.230.227.89Accuracy98.5299.8898.499.6199.8598.5799.8798.4699.6099.85Precision72.6990.3683.7299.7899.2765.8791.9492.4999.7999.61Recall78.2996.7476.1299.7992.2796.5893.7265.7799.7892.11F-score72.6293.4378.5899.7895.6478.3292.8276.8799.7895.7GRU with two layerTN98.5399.9399.2589.199.8198.6599.9199.4994.1199.82FP1.470.070.7510.90.191.350.090.515.890.18FN5.8539.2653.040.5419.997.449.7842.090.4913.73Accuracy98.4199.5997.2198.599.4698.4999.8397.8799.0199.58Precision63.8788.5872.0198.988.1665.4490.3382.0699.4089.44Recall94.1560.7446.9699.4680.0192.5690.2257.9199.5186.27F-score76.0979.7356.7899.1883.8576.6790.2767.9099.4687.83


### 4.2.1. Regular Machine Learning Using All Features

(1) Cross-Validation Results. Table 10 shows the machine learning models’ performance using the unseen testing WSN-DS dataset. For the normal class, RF is the highest performance model (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score 98.96%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.93%, 99.46%, and 98.20%, respectively. For the Grayhole class, DT is the highest performance model (accuracy of 99.95%, precision of 97.32%, recall of 96.89%, and F-score 97.1%). At the same time, NB is the worst performing model (accuracy of 92.95%, precision of 8.51%, recall of 80.00%, and F-score 15.38%). Similar to Blackhole class, RF is the highest performance model (accuracy of 99.87%, precision of 98.3%, recall of 98.47%, and F-score 98.39%). Regarding scheduling and flooding classes, RF obtained the highest performance by accuracy of 99.74% and 99.89%, respectively. However, NB is the worst performing model for both classes, including accuracy of 84.10% for scheduling and 90.15% for flooding. Yet, the NB model using Scheduling classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 84.65%.(2) Testing Results. As shown in the results, for the normal class, the RF model has achieved the highest performances among other models (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score 98.96%). However, the NB model has recorded the worst performances among other models (accuracy of 98.20%, precision of 97.07%, recall of 34.69%, and F-score 51.11%). For the grayhole class, DT and RF have achieved the highest performances among other models (accuracy of 99.95%). However, the NB model has recorded the worst performances among other models (accuracy of 92.95%, precision of 8.51%, recall of 80.0015.38%, and F-score 15.38%). Like the blackhole class, the RF model has achieved the highest performances among other models (accuracy of 99.87%, precision of 98.3%, a recall of 98.47%, and F-score of 98.39%). However, the NB model has recorded the worst performances among other models (accuracy of 94.40%, precision of 34.91%, recall of 47.76%, and F-score of 40.33%). Regarding scheduling class, the RF model has achieved the highest performances among other models (accuracy of 99.74%, precision of 99.84%, recall of 99.88%, and F-score of 99.86%). However, the NB model has recorded the worst performances among other models (accuracy of 84.10%, precision of 99.89%, recall of 82.58%, and F-score of 90.41%). Flooding class like the other classes, the RF model, has achieved the highest performances among other models (accuracy of 99.89%, precision of 99.78%, recall of 93.93%, and F-score of 96.77%). However, the NB model has recorded the worst performances among other models (accuracy of 90.15%, precision of 13.37%, recall of 84.01%, and F-score of 23.07%). Based on these results, RF and DT models for the grayhole class are the best performing models with respect to other models, while the NB model for scheduling class is the worst performing model.


### 4.2.2. Regular Machine Learning Using Selected Features

In this section, the machine learning performance results of applying feature selection using WSN-DS dataset are presented.(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the WSN-DS dataset with selected features, as shown in Table 11. As shown in the normal class results, RF has achieved the highest performances among other models and other classes (accuracy of 99.93%, precision of 98.16%, recall of 99.09%, and F-score of 98.62%). The DT model has achieved the second one, KNN is the third one, and the fourth one is NB. For the grayhole class, RF has achieved the highest performances among other models (accuracy of 99.92%, precision of 92.81%, recall of 99.04%, and F-score of 95.82%). In contrast, NB has done the worst performances (accuracy of 91.47%, precision of 7.39%, recall of 74.91%, and F-score of 13.44%). Like blackhole class, RF has achieved the highest performances among other models (accuracy of 99.86%, precision of 98.24%, recall of 98.11%, and F-score of 98.17%). In contrast, NB has done the worst performances (accuracy of 93.45%, precision of 23.26%, recall of 29.6%, and F-score of 26.04%). Regarding scheduling class, RF has achieved the highest performances among other models (accuracy of 99.69%, precision of 99.82%, recall of 99.83%, and F-score of 99.83%). In contrast, NB has done the worst performances (accuracy of 84.61%, precision of 95.14%, recall of 87.52%, and F-score of 91.17%). Flooding class like the other classes, RF has achieved the highest performances among other models (accuracy of 99.84%, precision of 97.84%, recall of 92.96%, and F-score of 95.33%). In contrast, NB has done the worst performances (accuracy of 99.23%, precision of 95.83%, recall of 59.07%, and F-score of 73.08%). Based on these results, the RF model using normal class is the best performing model concerning other models, while NB using Scheduling class is the worst performing model.(2) Testing Results. Table 10 shows the performance of the machine learning models using the unseen testing WSN-DS dataset. For the normal class, RF is the highest performance model (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score of 98.96%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.93%, 99.46%, and 98.20%, respectively. For the grayhole class, DT is the highest performance model (accuracy of 99.95%, precision of 97.32%, recall of 96.89%, and F-score of 97.1%). At the same time, NB is the worst performing model (accuracy of 92.95%, precision of 8.51%, recall of 80.00%, and F-score of 15.38%). Similar to blackhole class, RF is the highest performance model (accuracy of 99.87%, precision of 98.3%, recall of 98.47%, and F-score of 98.39%). Regarding scheduling and flooding classes, RF obtained the highest performance by accuracy of 99.74% and 99.89%, respectively. However, NB is the worst performing model for both classes, including accuracy of 84.10% for scheduling and 90.15% for flooding. Yet, the NB model using scheduling classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 84.65%.


### 4.2.3. Deep Learning Using All Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four deep learning models (LSTM and GRU, using one and two layers) over the WSN-DS dataset with all features, as shown in Table 12. As shown in the results, for the normal class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 100%, recall of 100%, and F-score of 100%). LSTM using two layers’ model has achieved the second one, and GRU with one layer and two layers’ models have almost similar performances which achieved the third one. For the grayhole class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.98%, precision of 99.92%, recall of 99.95%, and F-score of 99.93%). In contrast, GRU with two layers has done the second one, and LSTM using one layer and GRU with two layers has done similar performances ranked as a third one. Like blackhole class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 100%, precision of 100%, recall of 99.74%, and F-score of 99.87%). In contrast, GRU with one layer has done the worst performances (accuracy of 97.5%, precision of 75.67%, recall of 53.16%, and F-score of 62.23%). Regarding scheduling class, LSTM using one layer has achieved the highest performances among other models (accuracy of 99.98%, precision of 96.76%, recall of 96.81%, and F-score of 96.75%). Flooding class like the other classes, LSTM using one layer has achieved the highest performances among other models (accuracy of 100% and precision of 95%), while other models include LSTM using two layers, and GRU using one layer and two layers has achieved approximated performances in terms of accuracy such as 99.67%, 99.68%, and 99.7%, respectively. Based on these results, LSTM using one layer model for blackhole and flooding classes is the best performing model with respect to other models, while GRU using one and two layers for normal class is the worst performing model.(2) Testing Results. Table 12 shows the performance of the deep learning models using the unseen testing WSN-DS dataset. As shown in the results, for the normal class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.55%, precision of 66.47%, recall of 92.95%, and F-score of 77.51%). LSTM using two layers and GRU has one layer models have achieved the second one, and GRU with two layers has achieved the third one. For the grayhole class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 99.85%, precision of 86.93%, recall of 97.22%, and F-score of 91.79%). LSTM using one layer has performed the second one, LSTM using two layers and GRU with one layer have done the third one, and LSTM using one layer and GRU with two layers are ranked as a third one. Similar to blackhole class, GRU using two layers model has achieved the highest performances among other models and other classes (accuracy of 98.01%, precision of 79.48%, recall of 65.94%, and F-score 72.08%), while LSTM with one layer has done the worst performances (accuracy of 97.67%, precision of 77.93%, recall of 56.23%, and F-score 65.33%). Regarding scheduling class, GRU using two layers has achieved the highest performances among other models (accuracy of 99.23%, precision of 99.64%, recall of 99.52%, and F-score of 99.58%). For flooding class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.75%, precision of 96.11%, recall of 89.34%, and F-score of 92.60%). Based on these results, GRU using two layers’ model for grayhole is the best performing model with respect to other models, while GRU using one layer for blackhole class is the worst performing model.


### 4.2.4. Deep Learning Using Selected Features

(1) Cross-Validation Results. As shown in the result in Table 13, four deep learning models were over the WSN-DS dataset with selected features, and for the normal class, GRU using one layer model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 98.52%, precision of 72.69%, recall of 78.29%, and F-score of 72.62%). LSTM using one layer, GRU with two layers, and LSTM using two layers have been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the grayhole class, GRU using one layer model has achieved the highest performances among other models (accuracy of 99.88%, precision of 90.36%, recall of 96.74%, and F-score of 93.43%). In contrast, LSTM with one layer, GRU with one layer, and GRU with two layers have recorded the second, third, and fourth models based on their accuracy. Like the blackhole class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.4%, precision of 83.72%, recall of 76.12%, and F-score of 78.58%). In contrast, GRU with two-layer has done the worst performances (accuracy of 97.21%, precision of 72.01%, recall of 46.96%, and F-score of 56.78%).Regarding scheduling class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.61%, precision of 99.78%, recall of 99.79%, and F-score of 99.78%). Flooding class like the other classes, GRU using one layer has achieved the highest performances among other models (accuracy of 99.85%, precision of 99.27%, recall of 92.27%, and F-score of 95.64%). Based on these results, GRU using one layer model for grayhole is the best performing model with respect to other models, while GRU using two layers for the blackhole class is the worst performing model.(2) Testing Results. Table 13 shows the performance of the machine learning models using the unseen testing WSN-DS dataset. As shown in the results, for the normal class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.57%, precision of 65.87%, recall of 96.58%, and F-score of 78.32%). However, LSTM using two layers’ model has recorded the worst performances among other models and other classes (accuracy of 98.38%, precision of 63.25%, recall of 94.90%, and F-score of 75.91%). For the grayhole class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.88%, precision of 91.49%, recall of 94.81%, and F-score of 93.12%). GRU using two layers’ model has recorded the worst performances among other models and other classes (accuracy of 99.83%, precision of 90.33%, recall of 90.22%, and F-score of 90.27%). Like the blackhole class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.46%, precision of 92.49%, recall of 65.77%, and F-score of 76.87%). In contrast, LSTM with two layers has the worst performances (accuracy of 97.62%, precision of 75.66%, recall of 57.50%, and F-score of 65.34%). Regarding the scheduling class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.60%, precision of 99.79%, recall of 99.78%, and F-score 99.78%). In contrast, LSTM with two layers has done the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score 99.32%). Flooding class like the other classes, GRU using one layer model has achieved the highest performances among different models and other classes (accuracy of 99.85%, precision of 99.61%, recall of 92.11%, and F-score of 95.7%). In contrast, LSTM with two layers has the worst performances (accuracy of 99.53%, precision of 92.62%, recall of 80.12%, and F-score of 85.92%). Based on these results, LSTM using one layer model for grayhole is the best performing model with respect to other models, while LSTM using one layer for the blackhole class is the worst performing model.


## 4.2.1. Regular Machine Learning Using All Features

(1) Cross-Validation Results. Table 10 shows the machine learning models’ performance using the unseen testing WSN-DS dataset. For the normal class, RF is the highest performance model (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score 98.96%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.93%, 99.46%, and 98.20%, respectively. For the Grayhole class, DT is the highest performance model (accuracy of 99.95%, precision of 97.32%, recall of 96.89%, and F-score 97.1%). At the same time, NB is the worst performing model (accuracy of 92.95%, precision of 8.51%, recall of 80.00%, and F-score 15.38%). Similar to Blackhole class, RF is the highest performance model (accuracy of 99.87%, precision of 98.3%, recall of 98.47%, and F-score 98.39%). Regarding scheduling and flooding classes, RF obtained the highest performance by accuracy of 99.74% and 99.89%, respectively. However, NB is the worst performing model for both classes, including accuracy of 84.10% for scheduling and 90.15% for flooding. Yet, the NB model using Scheduling classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 84.65%.(2) Testing Results. As shown in the results, for the normal class, the RF model has achieved the highest performances among other models (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score 98.96%). However, the NB model has recorded the worst performances among other models (accuracy of 98.20%, precision of 97.07%, recall of 34.69%, and F-score 51.11%). For the grayhole class, DT and RF have achieved the highest performances among other models (accuracy of 99.95%). However, the NB model has recorded the worst performances among other models (accuracy of 92.95%, precision of 8.51%, recall of 80.0015.38%, and F-score 15.38%). Like the blackhole class, the RF model has achieved the highest performances among other models (accuracy of 99.87%, precision of 98.3%, a recall of 98.47%, and F-score of 98.39%). However, the NB model has recorded the worst performances among other models (accuracy of 94.40%, precision of 34.91%, recall of 47.76%, and F-score of 40.33%). Regarding scheduling class, the RF model has achieved the highest performances among other models (accuracy of 99.74%, precision of 99.84%, recall of 99.88%, and F-score of 99.86%). However, the NB model has recorded the worst performances among other models (accuracy of 84.10%, precision of 99.89%, recall of 82.58%, and F-score of 90.41%). Flooding class like the other classes, the RF model, has achieved the highest performances among other models (accuracy of 99.89%, precision of 99.78%, recall of 93.93%, and F-score of 96.77%). However, the NB model has recorded the worst performances among other models (accuracy of 90.15%, precision of 13.37%, recall of 84.01%, and F-score of 23.07%). Based on these results, RF and DT models for the grayhole class are the best performing models with respect to other models, while the NB model for scheduling class is the worst performing model.


## 4.2.2. Regular Machine Learning Using Selected Features

In this section, the machine learning performance results of applying feature selection using WSN-DS dataset are presented.(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the WSN-DS dataset with selected features, as shown in Table 11. As shown in the normal class results, RF has achieved the highest performances among other models and other classes (accuracy of 99.93%, precision of 98.16%, recall of 99.09%, and F-score of 98.62%). The DT model has achieved the second one, KNN is the third one, and the fourth one is NB. For the grayhole class, RF has achieved the highest performances among other models (accuracy of 99.92%, precision of 92.81%, recall of 99.04%, and F-score of 95.82%). In contrast, NB has done the worst performances (accuracy of 91.47%, precision of 7.39%, recall of 74.91%, and F-score of 13.44%). Like blackhole class, RF has achieved the highest performances among other models (accuracy of 99.86%, precision of 98.24%, recall of 98.11%, and F-score of 98.17%). In contrast, NB has done the worst performances (accuracy of 93.45%, precision of 23.26%, recall of 29.6%, and F-score of 26.04%). Regarding scheduling class, RF has achieved the highest performances among other models (accuracy of 99.69%, precision of 99.82%, recall of 99.83%, and F-score of 99.83%). In contrast, NB has done the worst performances (accuracy of 84.61%, precision of 95.14%, recall of 87.52%, and F-score of 91.17%). Flooding class like the other classes, RF has achieved the highest performances among other models (accuracy of 99.84%, precision of 97.84%, recall of 92.96%, and F-score of 95.33%). In contrast, NB has done the worst performances (accuracy of 99.23%, precision of 95.83%, recall of 59.07%, and F-score of 73.08%). Based on these results, the RF model using normal class is the best performing model concerning other models, while NB using Scheduling class is the worst performing model.(2) Testing Results. Table 10 shows the performance of the machine learning models using the unseen testing WSN-DS dataset. For the normal class, RF is the highest performance model (accuracy of 99.94%, precision of 98.45%, recall of 99.48%, and F-score of 98.96%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.93%, 99.46%, and 98.20%, respectively. For the grayhole class, DT is the highest performance model (accuracy of 99.95%, precision of 97.32%, recall of 96.89%, and F-score of 97.1%). At the same time, NB is the worst performing model (accuracy of 92.95%, precision of 8.51%, recall of 80.00%, and F-score of 15.38%). Similar to blackhole class, RF is the highest performance model (accuracy of 99.87%, precision of 98.3%, recall of 98.47%, and F-score of 98.39%). Regarding scheduling and flooding classes, RF obtained the highest performance by accuracy of 99.74% and 99.89%, respectively. However, NB is the worst performing model for both classes, including accuracy of 84.10% for scheduling and 90.15% for flooding. Yet, the NB model using scheduling classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 84.65%.


## 4.2.3. Deep Learning Using All Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four deep learning models (LSTM and GRU, using one and two layers) over the WSN-DS dataset with all features, as shown in Table 12. As shown in the results, for the normal class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 100%, recall of 100%, and F-score of 100%). LSTM using two layers’ model has achieved the second one, and GRU with one layer and two layers’ models have almost similar performances which achieved the third one. For the grayhole class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.98%, precision of 99.92%, recall of 99.95%, and F-score of 99.93%). In contrast, GRU with two layers has done the second one, and LSTM using one layer and GRU with two layers has done similar performances ranked as a third one. Like blackhole class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 100%, precision of 100%, recall of 99.74%, and F-score of 99.87%). In contrast, GRU with one layer has done the worst performances (accuracy of 97.5%, precision of 75.67%, recall of 53.16%, and F-score of 62.23%). Regarding scheduling class, LSTM using one layer has achieved the highest performances among other models (accuracy of 99.98%, precision of 96.76%, recall of 96.81%, and F-score of 96.75%). Flooding class like the other classes, LSTM using one layer has achieved the highest performances among other models (accuracy of 100% and precision of 95%), while other models include LSTM using two layers, and GRU using one layer and two layers has achieved approximated performances in terms of accuracy such as 99.67%, 99.68%, and 99.7%, respectively. Based on these results, LSTM using one layer model for blackhole and flooding classes is the best performing model with respect to other models, while GRU using one and two layers for normal class is the worst performing model.(2) Testing Results. Table 12 shows the performance of the deep learning models using the unseen testing WSN-DS dataset. As shown in the results, for the normal class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.55%, precision of 66.47%, recall of 92.95%, and F-score of 77.51%). LSTM using two layers and GRU has one layer models have achieved the second one, and GRU with two layers has achieved the third one. For the grayhole class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 99.85%, precision of 86.93%, recall of 97.22%, and F-score of 91.79%). LSTM using one layer has performed the second one, LSTM using two layers and GRU with one layer have done the third one, and LSTM using one layer and GRU with two layers are ranked as a third one. Similar to blackhole class, GRU using two layers model has achieved the highest performances among other models and other classes (accuracy of 98.01%, precision of 79.48%, recall of 65.94%, and F-score 72.08%), while LSTM with one layer has done the worst performances (accuracy of 97.67%, precision of 77.93%, recall of 56.23%, and F-score 65.33%). Regarding scheduling class, GRU using two layers has achieved the highest performances among other models (accuracy of 99.23%, precision of 99.64%, recall of 99.52%, and F-score of 99.58%). For flooding class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.75%, precision of 96.11%, recall of 89.34%, and F-score of 92.60%). Based on these results, GRU using two layers’ model for grayhole is the best performing model with respect to other models, while GRU using one layer for blackhole class is the worst performing model.


## 4.2.4. Deep Learning Using Selected Features

(1) Cross-Validation Results. As shown in the result in Table 13, four deep learning models were over the WSN-DS dataset with selected features, and for the normal class, GRU using one layer model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 98.52%, precision of 72.69%, recall of 78.29%, and F-score of 72.62%). LSTM using one layer, GRU with two layers, and LSTM using two layers have been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the grayhole class, GRU using one layer model has achieved the highest performances among other models (accuracy of 99.88%, precision of 90.36%, recall of 96.74%, and F-score of 93.43%). In contrast, LSTM with one layer, GRU with one layer, and GRU with two layers have recorded the second, third, and fourth models based on their accuracy. Like the blackhole class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.4%, precision of 83.72%, recall of 76.12%, and F-score of 78.58%). In contrast, GRU with two-layer has done the worst performances (accuracy of 97.21%, precision of 72.01%, recall of 46.96%, and F-score of 56.78%).Regarding scheduling class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.61%, precision of 99.78%, recall of 99.79%, and F-score of 99.78%). Flooding class like the other classes, GRU using one layer has achieved the highest performances among other models (accuracy of 99.85%, precision of 99.27%, recall of 92.27%, and F-score of 95.64%). Based on these results, GRU using one layer model for grayhole is the best performing model with respect to other models, while GRU using two layers for the blackhole class is the worst performing model.(2) Testing Results. Table 13 shows the performance of the machine learning models using the unseen testing WSN-DS dataset. As shown in the results, for the normal class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.57%, precision of 65.87%, recall of 96.58%, and F-score of 78.32%). However, LSTM using two layers’ model has recorded the worst performances among other models and other classes (accuracy of 98.38%, precision of 63.25%, recall of 94.90%, and F-score of 75.91%). For the grayhole class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.88%, precision of 91.49%, recall of 94.81%, and F-score of 93.12%). GRU using two layers’ model has recorded the worst performances among other models and other classes (accuracy of 99.83%, precision of 90.33%, recall of 90.22%, and F-score of 90.27%). Like the blackhole class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 98.46%, precision of 92.49%, recall of 65.77%, and F-score of 76.87%). In contrast, LSTM with two layers has the worst performances (accuracy of 97.62%, precision of 75.66%, recall of 57.50%, and F-score of 65.34%). Regarding the scheduling class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.60%, precision of 99.79%, recall of 99.78%, and F-score 99.78%). In contrast, LSTM with two layers has done the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score 99.32%). Flooding class like the other classes, GRU using one layer model has achieved the highest performances among different models and other classes (accuracy of 99.85%, precision of 99.61%, recall of 92.11%, and F-score of 95.7%). In contrast, LSTM with two layers has the worst performances (accuracy of 99.53%, precision of 92.62%, recall of 80.12%, and F-score of 85.92%). Based on these results, LSTM using one layer model for grayhole is the best performing model with respect to other models, while LSTM using one layer for the blackhole class is the worst performing model.


## 4.3. KDD Dataset

In this section, the results of applying four machine learning models (DT, KNN, RF, and NB) and four deep learning models (LSTM and GRU, using one and two layers), including cross-validation results and testing results, are described. Each machine learning model and deep learning model performance is discussed using full features and selected features to classify five classes of attack types includingDOS, R2L, U2R, Probe, and Normal. All the positive and negative rates results of the cross-validation and testing performances which are used to compute accuracy, precision, recall, and F-score matrices are presented in Tables 14–17.Table 14
The performance of machine learning for KDD dataset using all features.
ModelsEvaluation metricCross-validation performanceTesting performanceDOSNormalProbeR2LU2RDOSNormalProbeR2LU2RDTTNR99.9799.9899.9910010099.9599.9810099.99100FPR0.030.020.01000.050.0200.010FNR00.080.683.0125.8300.070.725.6350Accuracy99.9999.9799.9999.9999.9999.9999.9799.9999.9899.99Precision99.9999.9399.2798.174.1799.9999.8910097.166.67Recall10099.9299.3296.9974.1710099.9399.2894.3750F-score10099.9299.2997.5370.699.9999.9199.6495.7157.14KNNTNR99.6199.9499.9899.9910099.5599.8999.9699.99100.00FPR0.390.060.020.0100.450.110.040.010.00FNR0.010.189.765.651000.040.2912.278.45100.00Accuracy99.9199.9299.999.9899.9999.8999.8599.8599.9799.99Precision99.9199.7197.8296.31099.9099.4795.6795.590Recall99.9999.8290.2494.35099.9699.7187.7391.550.00F-score99.9599.7693.8795.28099.9399.5991.5393.530RFTNR99.9999.98100100100100.099.98100.00100.00100.00FPR0.010.020000.00.020.000.000.00FNR00.020.413.23400.00.010.803.5241.67Accuracy10099.9810099.99100100.099.9899.9999.99100.00Precision10099.999.9799.3693.75100.099.8999.8299.7087.50Recall10099.9899.5996.7760100.099.9999.2096.4858.33F-score10099.9499.7898.0477.8100.099.9499.5198.0670.00NBTNR73.2399.8797.5299.0297.8871.7199.8699.5499.1097.89FPR26.770.132.480.982.1228.290.140.460.902.11FNR3.0740.393.0498.65450.6341.05100.00100.0075.00Accuracy92.4492.7296.7498.7797.8894.1792.6598.6598.8797.88Precision93.93990.30.250.2493.8298.920.000.000.15Recall96.9359.76.961.355599.3758.950.000.0025.00F-score95.2674.485.74.220.696.5273.87000.31Table 15
The performance of machine learning for KDD dataset using selected features.
ModelsEvaluation metricCross-validation performanceTesting performanceDosNormalProbeR2LU2RDOSNormalProbeR2LU2RDTTNR98.7599.9599.9810010098.9199.9599.9799.99100.00FPR1.250.050.02001.090.050.030.010.00FNR0.060.1725.372.450.830.060.1822.762.0575.00Accuracy99.7299.9399.7699.9999.9999.7499.9399.7899.9999.99Precision99.7199.7696.7598.4375.9399.7499.7795.6097.9542.86Recall99.9499.8674.6397.649.1799.9499.8277.2497.9525.00F-score99.8399.884.259857.7899.8499.8085.4597.9531.58KNNTNR98.5599.8799.9799.9910098.7299.8699.9899.99100.00FPR1.450.130.030.0101.280.140.020.010.00FNR0.070.3827.6516.111000.070.3325.0719.94100.00Accuracy99.6799.8399.7399.9599.9999.7099.8399.7699.9499.99Precision99.6699.4195.8996.80.099.7099.3796.4594.790.0Recall99.9399.6272.3583.89099.9399.6774.9380.060.00F-score99.899.5182.4689.810.099.8199.5284.3486.800.0RFTNR98.7699.9499.9810010098.9199.9599.97100.00100.00FPR1.240.060.02001.090.050.030.000.00FNR0.060.1425.293.08400.060.1322.313.8158.33Accuracy99.7299.9399.7699.9910099.7499.9499.7899.9999.99Precision99.7199.7696.6699.7487.0499.7499.7796.1599.3971.43Recall99.9499.8674.7196.926099.9499.8777.6996.1941.67F-score99.8399.884.2698.371.8599.8499.8285.9497.7652.63NBTNR21.699.7597.6599.4979.4721.2799.7299.7299.5277.36FPR78.40.252.350.5120.5378.730.280.280.4822.64FNR24.797.3592.9798.6420.8324.9096.72100.00100.008.33Accuracy65.1382.4696.8799.2479.4764.8782.4898.8799.2777.36Precision80.4466.470.290.480.0980.2771.770.000.000.04Recall75.32.657.031.3679.1775.103.280.000.0091.67F-score77.785.085.613.560.1977.606.27000.07Table 16
The performance of deep learning for KDD dataset using LSTM and GRU with all features.
ModelEvaluation metricCross-validation performanceTesting performanceDOSNormalProbeR2LU2RDOSNormalProbeR2LU2RLSTM with one layerTNR98.799.8799.2491.8399.8899.9899.96100.0099.99100.00FPR1.30.130.768.170.120.020.040.000.010.00FNR10.429.6446.160.6811.670.010.061.247.6266.67Accuracy98.4699.7997.4798.6399.6899.9999.9599.9999.9799.99Precision65.6186.1674.4899.1793.07100.0099.8099.5597.2266.67Recall89.5890.3653.8499.3288.3399.9999.9498.7692.3833.33F-score75.688.262.2899.2490.62100.0099.8799.1594.7444.44LSTM with two layerTNR99.8999.7510099.9510099.9299.9399.9999.96100.00FPR0.110.2500.0500.080.070.010.040.00FNR0.180.352.6615.571000.010.292.2210.85100.00Accuracy99.8399.7399.9799.9199.9999.9899.8999.9899.9399.99Precision99.9798.8599.5882.2099.9899.7099.3784.920Recall99.8299.6597.3484.43099.9999.7197.7889.150.00F-score99.999.2598.4483.27099.9999.7098.5786.980GRU with one layerTNR99.8899.5610099.9610099.9299.90100.0099.97100.00FPR0.120.4400.0400.080.100.000.030.00FNR0.370.323.0714.281000.040.252.9311.73100.00Accuracy99.6799.5899.9799.9299.9999.9599.8799.9799.9399.99Precision99.979899.4684.57099.9899.5399.5486.740Recall99.6399.6896.9385.72099.9699.7597.0788.270.00F-score99.898.8398.1785.05099.9799.6498.2987.500GRU with two layerTNR99.8999.5399.9999.9610099.9699.87100.0099.97100.00FPR0.110.470.010.0400.040.130.000.030.00FNR0.380.282.6223.671000.050.192.6714.96100.00Accuracy99.6799.5699.9799.999.9999.9599.8699.9799.9399.99Precision99.9897.8799.286.37099.9999.4399.6487.350Recall99.6299.7297.3876.33099.9599.8197.3385.040.00F-score99.898.7898.2876.73099.9799.6298.4786.180Table 17
The performance of deep learning for KDD dataset using LSTM and GRU with selected features.
ModelEvaluation metricCross-validation performanceTesting performanceDOSNormalProbeR2LU2RDOSNormalProbeR2LU2RLSTM with one layerTNR66.9698.7510099.9910078.0698.50100.0099.99100.00FPR33.041.2500.01021.941.500.000.010.00FNR0.9530.6310079.181001.0619.57100.0077.13100.00Accuracy92.9893.5199.1399.7999.9994.9895.2799.1599.7999.99Precision92.9192.35084.040.095.0692.090.082.110.0Recall99.0569.37020.82098.9480.430.0022.870.00F-score95.8477.590.039.480.096.9685.870.035.780.0LSTM with two layerTNR81.5398.3799.9910010085.8398.37100.0099.99100.00FPR18.471.630.010014.171.630.000.010.00FNR1.2415.9387.6994.941001.4011.5076.0976.83100.00Accuracy95.4995.8299.2299.7699.9996.1796.6099.3599.7999.99Precision95.8291.7884.5891.370.096.7492.1998.1886.810.0Recall98.7684.0712.315.06098.6088.5023.9123.170.00F-score97.2687.7133.9439.520.097.6690.3138.4636.570.0GRU with one layerTNR78.7399.2210010010079.0099.19100.00100.00100.00FPR21.270.7800021.000.810.000.000.00FN0.3618.261001001000.3618.15100.00100.00100.00Accuracy95.6896.1199.1399.7599.9995.7296.0999.1599.7499.99Precision95.2595.770.00.00.095.2995.660.00.00.0Recall99.6481.7400099.6481.850.000.000.00F-score97.488.20.00.00.097.4288.220.00.00.0GRU with two layerTNR82.998.9499.9999.9810083.2599.3499.9899.99100.00FPR17.11.060.010.02016.750.660.020.010.00FNR0.7714.486.8373.341000.4614.1176.0976.54100.00Accuracy96.1496.5699.2499.899.9996.4596.9399.3499.7999.99Precision96.1394.6291.6780.40.096.2096.5993.0883.330.0Recall99.2385.613.1726.66099.5485.8923.9123.460.00F-score97.6589.8835.2839.920.097.8490.9238.0536.610.0


### 4.3.1. Regular Machine Learning Using All Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the KDD dataset with all features, as shown in Table 14. As shown in the results, for the Dos class, RF has achieved the highest performances among other models and other classes (accuracy of 100%, precision of 100%, recall of 100%, and F-score of 100%). The DT model has achieved the second one and KNN is the third one. NB has reached the lowest performances (accuracy of 92.44%, precision of 93.93%, recall of 96.93%, and F-score 95.26%). For the normal class, RF has achieved the highest performances among other models (accuracy of 99.98%, precision of 92.9%, recall of 99.98%, and F-score of 95.94%). In contrast, NB has the worst performances (accuracy of 92.72%, precision of 99%, recall of 59.7%, and F-score 74.48%). Like the probe class, RF has achieved the highest performances among other models (accuracy of 100%, precision of 99.97%, recall of 99.59%, and F-score of 99.78%). In contrast, NB has the worst performances (accuracy of 96.74%, precision of 0.3%, recall of 6.96%, and F-score of 5.7%). Regarding R2l class, RF has achieved the highest performances among other models (accuracy of 99.99%, precision of 99.36%, recall of 96.77%, and F-score of 98.04%). In contrast, NB has the worst performances (accuracy of 98.77%, precision of 0.25%, recall of 1.35%, and F-score of 4.22%). U2r class classes, RF has achieved the highest performance (accuracy of 100%, precision of 93.75%, and F-score of 77.8%), while DT has achieved the highest recall of 96.99%. KNN and NB have the worst performances. Based on these results, the RF model using the DoS class is the best performing model with respect to other models.(2) Testing Results. Table 14 shows the performance of the machine learning models using the unseen testing KDD dataset. For the RF model, DOS class has achieved the highest accuracy among other models and classes (accuracy of 100%, precision of 100%, recall of 100%, and F-score of 100%). However, NB has the DOS class’s worst performances (accuracy of 94.17%, precision of 93.82%, recall of 99.37%, and F-score of 96.52%). For the normal class, RF is the highest performance model (accuracy of 99.98%, precision of 99.89%, recall of 99.99%, and F-score of 98.94%). DT, KNN, and NB models have achieved the second, third, and fourth ranks based on accuracy over unseen data by 99.97%, 99.85%, and 92.65%, respectively. Similar to the probe class, DT is the highest performance model (accuracy of 99.99%, precision of 100%, recall of 99.28%, and F-score of 96.64%). RF, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.99%, 99.85%, and 98.65%, respectively. Regarding R2l and U2r classes, RF obtained the highest performance, while NB is the worst performing model for both classes. However, the NB model using normal classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 92.65%.


### 4.3.2. Regular Machine Learning Using Selected Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the KDD dataset with all features, as shown in Table 15. As shown in the results, for the DOS class, RF and DT have achieved the highest performances among other models and other classes (accuracy of 99.72%, precision of 99.71%, recall of 99.94%, and F-score of 99.83%). The KNN model has achieved the second one. NB has achieved the lowest performances (accuracy of 65.13%, precision of 80.44%, recall of 75.3%, and F-score of 77.78%). For the normal class, RF and DT have achieved the highest performances among other models (accuracy of 99.93%, precision of 99.76%, recall of 99.86%, and F-score of 99.8%), while NB has the worst performances (accuracy of 82.46%, precision of 66.47%, recall of 2.65%, and F-score of 5.08%). The probe class, RF has achieved the highest performances among other models (accuracy of 99.99%, precision of 99.74%, and F-score of 98.3%), while DT has achieved the highest recall of 97.6%. NB has the worst performances (accuracy of 96.87%, precision of 0.29%, recall of 7.03%, and F-score of 5.61%). Regarding R2l class, RF has achieved the highest performances among other models (accuracy of 100%, precision of 87.04%, recall of 60%, and F-score of 71.85%), while NB has the worst performances (accuracy of 99.24%, precision of 0.48%, recall of 1.36%, and F-score 3.56%). U2R classes, RF and DT, have achieved similar the highest performance. NB has the worst performances (accuracy of 79.47%, precision of 0.09%, recall of 79.17, and F-score of 0.19). Based on these results, RF and DT models for each class have the best performing model with respect to other models, while NB has the worst performances.(2) Testing Results. Table 15 shows the performance of the machine learning models using the unseen testing KDD dataset. For the RF and DT model, DOS class has achieved the highest accuracy among other models and classes (accuracy of 99.74%, precision of 99.74%, recall of 99.94%, and F-score of 99.84%). However, NB has the DOS class’s worst performances (accuracy of 64.87%, precision of 80.27%, recall of 75.10%, and F-score of 77.60%). For the normal class, DT and RF are the highest performance model (accuracy of 99.93%, precision of 99.77%, recall of 99.82%, and F-score of 99.80%). KNN and NB models have achieved the second and third ranks based on accuracy over unseen data by 99.83% and 82.48%, respectively. Similar to the probe class, RF is the highest performance model (accuracy of 99.78%, precision of 96.15%, recall of 77.69%, and F-score of 85.94%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.78%, 99.76%, and 98.87%, respectively. Regarding R2L and U2R classes, RF obtained the highest performance, while NB is the worst performing model for both classes.


### 4.3.3. Deep Learning Using All Features

(1) Cross-Validation Results. As shown in the result in Table 16, four deep learning models were over the KDD dataset with selected features; for the DOS class, LSTM using two layers’ model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 99.83%, precision of 99.97%, recall of 99.82%, and F-score of 99.9%). LSTM using one layer, GRU with one layer and two layers, and LSTM using one layer has been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the normal class, LSTM using two layers’ model has achieved the highest performances among other models (accuracy of 99.73%, precision of 98.85%, recall of 99.65%, and F-score of 99.25%). In contrast, LSTM with one layer has achieved the lowest performance (accuracy of 99.79%, precision of 86.16%, recall of 90.36%, and F-score of 88.2%). GRU with one layer and GRU with two layers have recorded the second, third, and accuracy. Like the probe class, LSTM using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.97%, precision of 99.58%, recall of 97.34%, and F-score of 98.44%). In contrast, LSTM with one layer has the worst performances (accuracy of 97.47%, precision of 74.48%, recall of 53.84%, and F-score of 62.28%). Regarding R2l class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.92%, precision of 84.57%, recall of 85.72%, and F-score of 85.05%). U2R class like the other classes, GRU using one layer has achieved the highest performances among other models accuracy of 99.68%, precision of 93.07%, recall of 88.33%, and F-score of 90.62%). Based on these results, LSTM using two layers’ model for DOS is the best performing model with respect to other models.(2) Testing Results. As shown in the result in Table 16, four deep learning models were over the KDD dataset with selected features; for the DOS class, LSTM using two layers’ model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 99.83%, precision of 99.97%, recall of 99.82%, and F-score of 99.9%). LSTM using one layer, GRU with one layer and two layers, and LSTM using one layer has been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the normal class, LSTM using two layers’ model has achieved the highest performances among other models (accuracy of 99.73%, precision of 98.85%, recall of 99.65%, and F-score of 99.25%). In contrast, LSTM with one layer has achieved the lowest performance accuracy of 99.79%, precision of 86.16%, recall of 90.36% and F-score of 88.2%). GRU with one layer and GRU with two layers have recorded the second and third and accuracy. Like the probe class, LSTM using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.97%, precision of 99.58%, recall of 97.34%, and F-score of 98.44%). Table 16 shows the performance of the deep learning models using the unseen testing KDD dataset. As shown in the results, for the DOS class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 100%, recall of 99.99%, and F-score of 100%). LSTM using two layers’ model and GRU models have similar performance. For the normal class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.95%, precision of 99.80%, recall of 99.94%, and F-score of 99.87%). LSTM with two layers and GRU using one layer and two layers model have recorded the similar performances. Like the probe class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 99.55%, recall of 98.76%, and F-score of 99.15%). Regarding the scheduling class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.60%, precision of 99.79%, recall of 99.78% and F-score99.78%). In contrast, LSTM with two layers has done the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score of 99.32%). Flooding class like the other classes, GRU using one layer model has achieved the highest performances among different models and other classes (accuracy of 99.85%, precision of 99.61%, recall of 92.11%, and F-score of 95.7%). In contrast, LSTM with two layers has the worst performances (accuracy of 99.53%, precision of 92.62%, recall of 80.12%, and F-score of 85.92%). Based on these results, LSTM using one layer model for grayhole is the best performing model for other models, while LSTM using one layer for the blackhole class is the worst performing model.


### 4.3.4. Deep Learning Using Selected Features

(1) Cross-Validation Results. As shown in the result, in Table 17, four deep learning models were over the KDD dataset with selected features; for the DOS class, GRU using two layers, model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 96.14%, precision of 96.13%, recall of 99.23%, and F-score of 97.65%). LSTM using one layer model has achieved the lowest performances based on its accuracy among other models and other classes (accuracy of 92.98%, precision of 92.91%, recall of 99.05%, and F-score of 95.84%). For the normal class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 96.56%, precision of 94.62%, recall of 85.6%, and F-score 89.88%). In contrast, LSTM with one layer has reached the lowest performance accuracy of 93.51%, precision of 92.35%, recall of 69.37%, and F-score of 77.59%). Similar to the probe class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.24%, precision of 99.58%, recall of 13.17%, and F-score of 35.28%). In comparison, LSTM with one and two layers and GRU with one layer have registered similar performance. Regarding R2l class, GRU using two layers has achieved the highest performances among other models (accuracy of 99.8%, precision of 80.4%, recall of 26.66%, and F-score of 39.92%). U2R class is like the other classes; all deep learning models have recorded the same performance (accuracy of 99.99%, precision of 0%, recall of 0%, and F-score 0%). Based on these results, all models for U2R are the worst performance concerning other models.(2) Testing Results. Table 17 shows the performance of the deep learning models using the unseen testing KDD dataset. As shown in the results, for the DOS class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 96.45%, precision of 96.20%, recall of 99.54%, and F-score of 97.84%). In contrast, LSTM with one layer has registered the lowest performance (accuracy of 94.98%, precision of 95.06%, recall of 98.94%, and F-score of 96.96%). For the normal class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 96.93%, precision of 96.59%, recall of 85.89%, and F-score of 90.92%). LSTM with one layer has recorded the worst performances (accuracy of 95.27%, precision of 92.09%, recall of 80.43%, and F-score of 85.87%). Like the probe class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.24%, precision of 91.67%, recall of 23.91%, and F-score of 38.05%). Regarding R2L class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.79%, precision of 83.33%, recall of 23.46%, and F-score of 36.61%). In comparison, LSTM with two layers has the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score of 99.32%). For U2R class, all models have achieved the worst performance. Based on these results, GRU using two layers’ model have registered the best performance.


## 4.3.1. Regular Machine Learning Using All Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the KDD dataset with all features, as shown in Table 14. As shown in the results, for the Dos class, RF has achieved the highest performances among other models and other classes (accuracy of 100%, precision of 100%, recall of 100%, and F-score of 100%). The DT model has achieved the second one and KNN is the third one. NB has reached the lowest performances (accuracy of 92.44%, precision of 93.93%, recall of 96.93%, and F-score 95.26%). For the normal class, RF has achieved the highest performances among other models (accuracy of 99.98%, precision of 92.9%, recall of 99.98%, and F-score of 95.94%). In contrast, NB has the worst performances (accuracy of 92.72%, precision of 99%, recall of 59.7%, and F-score 74.48%). Like the probe class, RF has achieved the highest performances among other models (accuracy of 100%, precision of 99.97%, recall of 99.59%, and F-score of 99.78%). In contrast, NB has the worst performances (accuracy of 96.74%, precision of 0.3%, recall of 6.96%, and F-score of 5.7%). Regarding R2l class, RF has achieved the highest performances among other models (accuracy of 99.99%, precision of 99.36%, recall of 96.77%, and F-score of 98.04%). In contrast, NB has the worst performances (accuracy of 98.77%, precision of 0.25%, recall of 1.35%, and F-score of 4.22%). U2r class classes, RF has achieved the highest performance (accuracy of 100%, precision of 93.75%, and F-score of 77.8%), while DT has achieved the highest recall of 96.99%. KNN and NB have the worst performances. Based on these results, the RF model using the DoS class is the best performing model with respect to other models.(2) Testing Results. Table 14 shows the performance of the machine learning models using the unseen testing KDD dataset. For the RF model, DOS class has achieved the highest accuracy among other models and classes (accuracy of 100%, precision of 100%, recall of 100%, and F-score of 100%). However, NB has the DOS class’s worst performances (accuracy of 94.17%, precision of 93.82%, recall of 99.37%, and F-score of 96.52%). For the normal class, RF is the highest performance model (accuracy of 99.98%, precision of 99.89%, recall of 99.99%, and F-score of 98.94%). DT, KNN, and NB models have achieved the second, third, and fourth ranks based on accuracy over unseen data by 99.97%, 99.85%, and 92.65%, respectively. Similar to the probe class, DT is the highest performance model (accuracy of 99.99%, precision of 100%, recall of 99.28%, and F-score of 96.64%). RF, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.99%, 99.85%, and 98.65%, respectively. Regarding R2l and U2r classes, RF obtained the highest performance, while NB is the worst performing model for both classes. However, the NB model using normal classes has the lowest accuracy performance among all models and classes for unseen data in terms of accuracy, 92.65%.


## 4.3.2. Regular Machine Learning Using Selected Features

(1) Cross-Validation Results. This section discusses the 10-fold CV results of four machine learning models (DT, KNN, RF, and NB) over the KDD dataset with all features, as shown in Table 15. As shown in the results, for the DOS class, RF and DT have achieved the highest performances among other models and other classes (accuracy of 99.72%, precision of 99.71%, recall of 99.94%, and F-score of 99.83%). The KNN model has achieved the second one. NB has achieved the lowest performances (accuracy of 65.13%, precision of 80.44%, recall of 75.3%, and F-score of 77.78%). For the normal class, RF and DT have achieved the highest performances among other models (accuracy of 99.93%, precision of 99.76%, recall of 99.86%, and F-score of 99.8%), while NB has the worst performances (accuracy of 82.46%, precision of 66.47%, recall of 2.65%, and F-score of 5.08%). The probe class, RF has achieved the highest performances among other models (accuracy of 99.99%, precision of 99.74%, and F-score of 98.3%), while DT has achieved the highest recall of 97.6%. NB has the worst performances (accuracy of 96.87%, precision of 0.29%, recall of 7.03%, and F-score of 5.61%). Regarding R2l class, RF has achieved the highest performances among other models (accuracy of 100%, precision of 87.04%, recall of 60%, and F-score of 71.85%), while NB has the worst performances (accuracy of 99.24%, precision of 0.48%, recall of 1.36%, and F-score 3.56%). U2R classes, RF and DT, have achieved similar the highest performance. NB has the worst performances (accuracy of 79.47%, precision of 0.09%, recall of 79.17, and F-score of 0.19). Based on these results, RF and DT models for each class have the best performing model with respect to other models, while NB has the worst performances.(2) Testing Results. Table 15 shows the performance of the machine learning models using the unseen testing KDD dataset. For the RF and DT model, DOS class has achieved the highest accuracy among other models and classes (accuracy of 99.74%, precision of 99.74%, recall of 99.94%, and F-score of 99.84%). However, NB has the DOS class’s worst performances (accuracy of 64.87%, precision of 80.27%, recall of 75.10%, and F-score of 77.60%). For the normal class, DT and RF are the highest performance model (accuracy of 99.93%, precision of 99.77%, recall of 99.82%, and F-score of 99.80%). KNN and NB models have achieved the second and third ranks based on accuracy over unseen data by 99.83% and 82.48%, respectively. Similar to the probe class, RF is the highest performance model (accuracy of 99.78%, precision of 96.15%, recall of 77.69%, and F-score of 85.94%). DT, KNN, and NB models have achieved the second, third, and fourth ranks on the average of accuracy over unseen data by 99.78%, 99.76%, and 98.87%, respectively. Regarding R2L and U2R classes, RF obtained the highest performance, while NB is the worst performing model for both classes.


## 4.3.3. Deep Learning Using All Features

(1) Cross-Validation Results. As shown in the result in Table 16, four deep learning models were over the KDD dataset with selected features; for the DOS class, LSTM using two layers’ model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 99.83%, precision of 99.97%, recall of 99.82%, and F-score of 99.9%). LSTM using one layer, GRU with one layer and two layers, and LSTM using one layer has been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the normal class, LSTM using two layers’ model has achieved the highest performances among other models (accuracy of 99.73%, precision of 98.85%, recall of 99.65%, and F-score of 99.25%). In contrast, LSTM with one layer has achieved the lowest performance (accuracy of 99.79%, precision of 86.16%, recall of 90.36%, and F-score of 88.2%). GRU with one layer and GRU with two layers have recorded the second, third, and accuracy. Like the probe class, LSTM using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.97%, precision of 99.58%, recall of 97.34%, and F-score of 98.44%). In contrast, LSTM with one layer has the worst performances (accuracy of 97.47%, precision of 74.48%, recall of 53.84%, and F-score of 62.28%). Regarding R2l class, GRU using one layer has achieved the highest performances among other models (accuracy of 99.92%, precision of 84.57%, recall of 85.72%, and F-score of 85.05%). U2R class like the other classes, GRU using one layer has achieved the highest performances among other models accuracy of 99.68%, precision of 93.07%, recall of 88.33%, and F-score of 90.62%). Based on these results, LSTM using two layers’ model for DOS is the best performing model with respect to other models.(2) Testing Results. As shown in the result in Table 16, four deep learning models were over the KDD dataset with selected features; for the DOS class, LSTM using two layers’ model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 99.83%, precision of 99.97%, recall of 99.82%, and F-score of 99.9%). LSTM using one layer, GRU with one layer and two layers, and LSTM using one layer has been ranked as the second, third, and fourth models, respectively, based on their accuracy. For the normal class, LSTM using two layers’ model has achieved the highest performances among other models (accuracy of 99.73%, precision of 98.85%, recall of 99.65%, and F-score of 99.25%). In contrast, LSTM with one layer has achieved the lowest performance accuracy of 99.79%, precision of 86.16%, recall of 90.36% and F-score of 88.2%). GRU with one layer and GRU with two layers have recorded the second and third and accuracy. Like the probe class, LSTM using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.97%, precision of 99.58%, recall of 97.34%, and F-score of 98.44%). Table 16 shows the performance of the deep learning models using the unseen testing KDD dataset. As shown in the results, for the DOS class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 100%, recall of 99.99%, and F-score of 100%). LSTM using two layers’ model and GRU models have similar performance. For the normal class, LSTM using one layer model has achieved the highest performances among other models (accuracy of 99.95%, precision of 99.80%, recall of 99.94%, and F-score of 99.87%). LSTM with two layers and GRU using one layer and two layers model have recorded the similar performances. Like the probe class, LSTM using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.99%, precision of 99.55%, recall of 98.76%, and F-score of 99.15%). Regarding the scheduling class, GRU using one layer model has achieved the highest performances among other models and other classes (accuracy of 99.60%, precision of 99.79%, recall of 99.78% and F-score99.78%). In contrast, LSTM with two layers has done the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score of 99.32%). Flooding class like the other classes, GRU using one layer model has achieved the highest performances among different models and other classes (accuracy of 99.85%, precision of 99.61%, recall of 92.11%, and F-score of 95.7%). In contrast, LSTM with two layers has the worst performances (accuracy of 99.53%, precision of 92.62%, recall of 80.12%, and F-score of 85.92%). Based on these results, LSTM using one layer model for grayhole is the best performing model for other models, while LSTM using one layer for the blackhole class is the worst performing model.


## 4.3.4. Deep Learning Using Selected Features

(1) Cross-Validation Results. As shown in the result, in Table 17, four deep learning models were over the KDD dataset with selected features; for the DOS class, GRU using two layers, model has achieved the highest performances based on its accuracy among other models and other classes (accuracy of 96.14%, precision of 96.13%, recall of 99.23%, and F-score of 97.65%). LSTM using one layer model has achieved the lowest performances based on its accuracy among other models and other classes (accuracy of 92.98%, precision of 92.91%, recall of 99.05%, and F-score of 95.84%). For the normal class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 96.56%, precision of 94.62%, recall of 85.6%, and F-score 89.88%). In contrast, LSTM with one layer has reached the lowest performance accuracy of 93.51%, precision of 92.35%, recall of 69.37%, and F-score of 77.59%). Similar to the probe class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.24%, precision of 99.58%, recall of 13.17%, and F-score of 35.28%). In comparison, LSTM with one and two layers and GRU with one layer have registered similar performance. Regarding R2l class, GRU using two layers has achieved the highest performances among other models (accuracy of 99.8%, precision of 80.4%, recall of 26.66%, and F-score of 39.92%). U2R class is like the other classes; all deep learning models have recorded the same performance (accuracy of 99.99%, precision of 0%, recall of 0%, and F-score 0%). Based on these results, all models for U2R are the worst performance concerning other models.(2) Testing Results. Table 17 shows the performance of the deep learning models using the unseen testing KDD dataset. As shown in the results, for the DOS class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 96.45%, precision of 96.20%, recall of 99.54%, and F-score of 97.84%). In contrast, LSTM with one layer has registered the lowest performance (accuracy of 94.98%, precision of 95.06%, recall of 98.94%, and F-score of 96.96%). For the normal class, GRU using two layers’ model has achieved the highest performances among other models (accuracy of 96.93%, precision of 96.59%, recall of 85.89%, and F-score of 90.92%). LSTM with one layer has recorded the worst performances (accuracy of 95.27%, precision of 92.09%, recall of 80.43%, and F-score of 85.87%). Like the probe class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.24%, precision of 91.67%, recall of 23.91%, and F-score of 38.05%). Regarding R2L class, GRU using two layers’ model has achieved the highest performances among other models and other classes (accuracy of 99.79%, precision of 83.33%, recall of 23.46%, and F-score of 36.61%). In comparison, LSTM with two layers has the worst performances (accuracy of 98.76%, precision of 99.44%, recall of 99.20%, and F-score of 99.32%). For U2R class, all models have achieved the worst performance. Based on these results, GRU using two layers’ model have registered the best performance.


## 5. Discussion

We examine the four machine learning models (DT, KNN, RF, and NB) and four deep learning models (LSTM and GRU, using one and two layers), including cross-validation results and testing using WSN-DS and KKD datasets. Table18 describes the summary of the used datasets including the number of all samples, the number of trained samples, the number of testing samples, the number of all features, the number of selected features, and the number of classified classes.Table 18
The summary of the used datasets.
DatasetWSN-DSKDDNumber of all samples374662311029Number of trained samples280995307916Number of testing samples93666131964Number of all features1942Number of selected features614Number of classified classes55


### 5.1. Regular Machine Learning

The results of machine learning cross-validation performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure3. Considering all feature results for cross-validation performance, the normal class using RF has the best performance (accuracy of 99.95%), while the NB model using the scheduling class has achieved the worst performance among all models and classes (accuracy of 84.47%) (see Figure 3(a)). Similar to the selected feature results, the normal class using RF has the best performance (accuracy of 99.93%), while the scheduling class, using the NM model, has achieved the worst performance among all models and classes (accuracy of 84.61%) (see Figure 3(b)). The results of machine learning testing performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure 4. Considering all features’ results for unseen dataset, the grayhole class using RF has the best performance (accuracy of 99.95%), while the scheduling class using the NB model has achieved the worst performance among all models and classes (accuracy of 84.1%) (see Figure 4(a)). Similar to the selected features’ results, the grayhole class using RF has the best performance (accuracy of 99.94%), while the scheduling class using the NB model has achieved the worst performance among all models and classes (accuracy of 84.65%) (see Figure 4(b)).Figure 3
The results of machine learning cross-validation performance for the WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 4
The results of machine learning testing performance for WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)The results of machine learning cross-validation performance based on the accuracy for KDD dataset using all features and selected features are depicted in Figure5. Considering all features results for cross-validation performance, DOS and U2R classes using RF have the best performance (accuracy of 100%), while the NB model using the DOS class has achieved the worst performance among all models and classes (accuracy of 92.44%) (see Figure 5(a)). Similar to the selected features’ results, U2R class using RF has the best performance (accuracy of 100%), while the DOS class using the NB model has achieved the worst performance among all models and classes (accuracy of 65.13%) (see Figure 3(b)). The results of machine learning testing performance based on the accuracy for the WSN dataset using all features and selected features are depicted in Figure 6. Considering all features’ results for the unseen dataset, DOS, normal, and U2R classes using RF have the best performance (accuracy of 100%), while the normal class using the NB model has achieved the worst performance among all models and classes (accuracy of 92.65%) (see Figure 6(a)). Similar to the selected features’ results, R2L and U2R classes, using RF, DT, and KNN, have the best performance (accuracy of 99.99%), while the DOS class, using the NB model, has achieved the worst performance among all models and classes (accuracy of 64.87%) (see Figure 6(b)).Figure 5
The results of machine learning cross-validation performance for KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 6
The results of machine learning testing performance for KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)


### 5.2. Deep Learning

The results of deep learning cross-validation performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure7. Considering all features results for cross-validation performance, the flooding class, using LSTM with one layer, has the best performance (accuracy of 100%), while the blackhole class, using GRU with the one layer model, has achieved the worst performance among all models and classes (accuracy of 97.5%) (see Figure 7(a)). Similar to the selected features’ results, the grayhole class, using LSTM with one layer, has the best performance (accuracy of 99.84%), while the blackhole class, using GRU with the two layers’ model, has achieved the worst performance among all models and classes (accuracy of 97.21%) (see Figure 7(b)). The results of deep learning testing performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure 8. Considering all features’ results for unseen dataset, the grayhole class, using GRU with the two layers’ model, has the best performance (accuracy of 99.85%), while the blackhole class, using GRU with the two layers’ model, has achieved the worst performance among all models and classes (accuracy of 98.01%) (see Figure 8(a)). Similar to the selected features results, the grayhole class, using LSTM with the one layer model, has the best performance (accuracy of 99.88%), while the blackhole class, using LSTM with the two layers’ model, has achieved the worst performance among all models and classes (accuracy of 97.62%) (see Figure 8(b)).Figure 7
The results of deep learning cross-validation performance for WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 8
The results of deep learning testing performance for WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)The results of deep learning cross-validation performance based on the accuracy for KDD dataset using all features and selected features are depicted in Figure9. Considering all features results for cross-validation performance, U2R class using LSTM with two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the DOS class using LSTM with one layer model has achieved the worst performance among all models and classes (accuracy of 98.46%) (see Figure 9(a)). Similar to the selected features results, U2R class using LSTM with one and two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the normal class using LSTM with the one layer model has achieved the worst performance among all models and classes (accuracy of 93.51%) (see Figure 9(b)). The results of deep learning testing performance based on the accuracy for KDD dataset using all features and selected features is depicted in Figure 10. Considering all features’ results for unseen dataset, U2R and Dos classes using LSTM with one and two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the normal class using GRU with the two layers’ model has achieved the worst performance among all models and classes (accuracy of 99.86%) (see Figure 10(a)). Similar to the selected features’ results, the U2R class using LSTM with one and two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the DOS class using GRU with the one layer model has achieved the worst performance among all models and classes (accuracy of 95.72%) (see Figure 10(b)).Figure 9
The results of deep learning cross-validation performance for the KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 10
The results of deep learning testing performance for the KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)


### 5.3. Summary

Many research studies in AI-based IDS area have used machine learning and deep learning models. Each of these models possesses its strengths and weaknesses, making them suitable for a particular attack type. Regarding this work, not only do we use machine learning and deep learning models, but an in-depth investigation of performance analysis has been carried out based on the chosen datasets. The performance analysis and comparison of these models on IDS datasets show no superiority of one model among the chosen datasets using all features and selected features. Furthermore, these findings lead to better knowledge and understand the interpretability for choosing the right model to enhance IDS trust. In particular, the authors in [24] have addressed the explainable artificial intelligence (XAI) concept to improve the trust management by exploring the decision tree model in the area of IDS. Compared to our work, we have provided a performance-based comparison using machine learning and deep learning models to investigate the trust impact based on the accuracy of the trusted AI-based systems regarding IDs’ malicious data.


## 5.1. Regular Machine Learning

The results of machine learning cross-validation performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure3. Considering all feature results for cross-validation performance, the normal class using RF has the best performance (accuracy of 99.95%), while the NB model using the scheduling class has achieved the worst performance among all models and classes (accuracy of 84.47%) (see Figure 3(a)). Similar to the selected feature results, the normal class using RF has the best performance (accuracy of 99.93%), while the scheduling class, using the NM model, has achieved the worst performance among all models and classes (accuracy of 84.61%) (see Figure 3(b)). The results of machine learning testing performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure 4. Considering all features’ results for unseen dataset, the grayhole class using RF has the best performance (accuracy of 99.95%), while the scheduling class using the NB model has achieved the worst performance among all models and classes (accuracy of 84.1%) (see Figure 4(a)). Similar to the selected features’ results, the grayhole class using RF has the best performance (accuracy of 99.94%), while the scheduling class using the NB model has achieved the worst performance among all models and classes (accuracy of 84.65%) (see Figure 4(b)).Figure 3
The results of machine learning cross-validation performance for the WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 4
The results of machine learning testing performance for WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)The results of machine learning cross-validation performance based on the accuracy for KDD dataset using all features and selected features are depicted in Figure5. Considering all features results for cross-validation performance, DOS and U2R classes using RF have the best performance (accuracy of 100%), while the NB model using the DOS class has achieved the worst performance among all models and classes (accuracy of 92.44%) (see Figure 5(a)). Similar to the selected features’ results, U2R class using RF has the best performance (accuracy of 100%), while the DOS class using the NB model has achieved the worst performance among all models and classes (accuracy of 65.13%) (see Figure 3(b)). The results of machine learning testing performance based on the accuracy for the WSN dataset using all features and selected features are depicted in Figure 6. Considering all features’ results for the unseen dataset, DOS, normal, and U2R classes using RF have the best performance (accuracy of 100%), while the normal class using the NB model has achieved the worst performance among all models and classes (accuracy of 92.65%) (see Figure 6(a)). Similar to the selected features’ results, R2L and U2R classes, using RF, DT, and KNN, have the best performance (accuracy of 99.99%), while the DOS class, using the NB model, has achieved the worst performance among all models and classes (accuracy of 64.87%) (see Figure 6(b)).Figure 5
The results of machine learning cross-validation performance for KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 6
The results of machine learning testing performance for KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)


## 5.2. Deep Learning

The results of deep learning cross-validation performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure7. Considering all features results for cross-validation performance, the flooding class, using LSTM with one layer, has the best performance (accuracy of 100%), while the blackhole class, using GRU with the one layer model, has achieved the worst performance among all models and classes (accuracy of 97.5%) (see Figure 7(a)). Similar to the selected features’ results, the grayhole class, using LSTM with one layer, has the best performance (accuracy of 99.84%), while the blackhole class, using GRU with the two layers’ model, has achieved the worst performance among all models and classes (accuracy of 97.21%) (see Figure 7(b)). The results of deep learning testing performance based on the accuracy for WSN dataset using all features and selected features are depicted in Figure 8. Considering all features’ results for unseen dataset, the grayhole class, using GRU with the two layers’ model, has the best performance (accuracy of 99.85%), while the blackhole class, using GRU with the two layers’ model, has achieved the worst performance among all models and classes (accuracy of 98.01%) (see Figure 8(a)). Similar to the selected features results, the grayhole class, using LSTM with the one layer model, has the best performance (accuracy of 99.88%), while the blackhole class, using LSTM with the two layers’ model, has achieved the worst performance among all models and classes (accuracy of 97.62%) (see Figure 8(b)).Figure 7
The results of deep learning cross-validation performance for WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 8
The results of deep learning testing performance for WSN dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)The results of deep learning cross-validation performance based on the accuracy for KDD dataset using all features and selected features are depicted in Figure9. Considering all features results for cross-validation performance, U2R class using LSTM with two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the DOS class using LSTM with one layer model has achieved the worst performance among all models and classes (accuracy of 98.46%) (see Figure 9(a)). Similar to the selected features results, U2R class using LSTM with one and two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the normal class using LSTM with the one layer model has achieved the worst performance among all models and classes (accuracy of 93.51%) (see Figure 9(b)). The results of deep learning testing performance based on the accuracy for KDD dataset using all features and selected features is depicted in Figure 10. Considering all features’ results for unseen dataset, U2R and Dos classes using LSTM with one and two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the normal class using GRU with the two layers’ model has achieved the worst performance among all models and classes (accuracy of 99.86%) (see Figure 10(a)). Similar to the selected features’ results, the U2R class using LSTM with one and two layers and GRU using one and two layers have the best performance (accuracy of 99.99%), while the DOS class using GRU with the one layer model has achieved the worst performance among all models and classes (accuracy of 95.72%) (see Figure 10(b)).Figure 9
The results of deep learning cross-validation performance for the KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)Figure 10
The results of deep learning testing performance for the KDD dataset: (a) accuracy using all features and (b) accuracy using selected features.
(a)(b)


## 5.3. Summary

Many research studies in AI-based IDS area have used machine learning and deep learning models. Each of these models possesses its strengths and weaknesses, making them suitable for a particular attack type. Regarding this work, not only do we use machine learning and deep learning models, but an in-depth investigation of performance analysis has been carried out based on the chosen datasets. The performance analysis and comparison of these models on IDS datasets show no superiority of one model among the chosen datasets using all features and selected features. Furthermore, these findings lead to better knowledge and understand the interpretability for choosing the right model to enhance IDS trust. In particular, the authors in [24] have addressed the explainable artificial intelligence (XAI) concept to improve the trust management by exploring the decision tree model in the area of IDS. Compared to our work, we have provided a performance-based comparison using machine learning and deep learning models to investigate the trust impact based on the accuracy of the trusted AI-based systems regarding IDs’ malicious data.


## 6. Conclusion and Future Work

In this paper, a comparison study is introduced to investigate intrusion detection’s trust impact, including the data, methodology, and expert accountability by analyzing machine learning and deep learning models’ performance. The developed phases of the comparison study have two-folds. The first comparison is made using four regular machine learning models, including DT, KNN, RF, and NB. The second comparison is made using four traditional deep learning models, including LSTM (one and two layers) and GRU (one and two layers). Two datasets are used to classify the attack type in IDS, including WSN-DS and KDD. The experimental results are significantly demonstrated, considering the data, methodology, and expert accountability causes misleading predictions, making the system vulnerable to attacks, and leading to zero-trust security for critical systems. Therefore, for future work, we plan to use XAI concept to enhance trust management by exploring machine learning models and deep learning in IDS.



---

*Source: 5538896-2021-03-08.xml*