# Explaining Machine Learning-Based Feature Selection of IDS for IoT and CPS Devices

Sesan Akintade, Seongtae Kim, Kaushik Roy

► To cite this version:

Sesan Akintade, Seongtae Kim, Kaushik Roy. Explaining Machine Learning-Based Feature Selection of IDS for IoT and CPS Devices. 19th IFIP International Conference on Artificial Intelligence Applications and Innovations (AIAI), Jun 2023, León, Spain. pp.69-80, 10.1007/978-3-031-34107-6_6 hal-05498059

HAL Id: hal-05498059

https://inria.hal.science/hal-05498059v1

Submitted on 6 Feb 2026

HAL is a multi-disciplinary open access
archive for the deposit and dissemination of sci-
entific research documents, whether they are pub-
lished or not. The documents may come from
teaching and research institutions in France or
abroad, or from public or private research centers.

L'archive ouverte pluridisciplinaire HAL, est
destinée au dépôt et à la diffusion de documents
scientifiques de niveau recherche, publiés ou non,
émanant des établissements d'enseignement et de
recherche français ou étrangers, des laboratoires
publics ou privés.

<figure><img src="image_1.png" /></figure>

Distributed under a Creative Commons CC BY 4.0 - Attribution - International License
<figure><img src="image_2.png" /></figure>

ifip

International Federation for Information Processing

This document is the original author manuscript of a paper submitted to an IFIP
conference proceedings or other IFIP publication by Springer Nature. As such, there
may be some differences in the official published version of the paper. Such
differences, if any, are usually due to reformatting during preparation for publication or
minor corrections made by the author(s) during final proofreading of the publication
manuscript.
# Explaining Machine Learning-Based Feature Selection of IDS for IoT and CPS Devices

Sesan Akintade(*), Seongtae Kim, and Kaushik Roy

North Carolina Agricultural and Technical State University, 1601 E Market Street,
Greensboro, NC 27411, USA

sfakintade@aggies.ncat.edu, {skim,kroy}@ncat.edu

**Abstract.** In training machine learning and artificial intelligence models for Intrusion Detection Systems (IDS), feature selection plays a critical role in evaluating the prediction performance and explainability of the trained model. The feature selection in designing the IDS is often hindered by the volume, variety, and veracity of the data generated from Internet-of-Things (IoT) and Cyber-Physical Systems (CPS) devices. In this paper, we explored selecting the best subset of features to reduce the feature space of high-dimensional datasets and thereby improve performance, explainability, and computing time. We incorporated the feature selection method of permutation importance in XGB models and prediction explainability methods, such as SHAP and LIME. Using two publicly available IDS datasets, NSL-KDD and CCID-V1, our feature selection-based XBG model for the NSL-KDD data reduced features from 42 to 20 with an AUC score of 0.8751 from the previous 0.8530 with 60% improvement in training time. A similar model for the CCID-V1 data reduced the features from 82 to 22 and achieved an AUC of 0.9999 with a 46% improvement in computing time. We also observed that SHAP and LIME explanations of the prediction showed consistent results in selecting important features. Our study demonstrated that the feature selection achieved an improvement in performance and explainability along with lower training time, which increases the usability of our model for the design of IDS.

**Keywords:** Internet-of-Things · Cyber Physical Systems · Intrusion Detection Systems · Explainability · Feature Selection

## 1 Introduction

Cloud computing entails the process of provisioning computing services like storage, software, and networking over the Internet. The ever-increasing availability of cloud platforms, inexpensive sensors, and continuous advances in Artificial Intelligence (AI) technologies have led to the proliferation of devices with the Internet of Things (IoT) and Cyber-Physical Systems (CPS). An IoT is a
technology that connects and shares information between devices through the Internet. At the same time, a CPS is an interconnected intelligent system that uses digital control to manage the physical environment. The diverse applications of IoT and CPS, with the concurrent offering of different services, have exposed the connected devices to threats and attacks [4,12]. Some of the common attacks include phishing, SQL injections, denial-of-service (DoS) attacks, malware attacks, remote-to-local attacks (R2L), and zero-day exploitations [13]. Cybersecurity offers a solution to protecting interconnected networks, cloud computing devices, and the information transmitted from cyber-attacks [18]. One of the significant cybersecurity technologies is the Intrusion Detection System (IDS). IDS monitors networks, data transmission, policies, and activities of connected devices to identify attacks within the networks and reports such attacks to a network administrator [2].

The design and network architecture of IoT devices are always in a state of flux, with many constraints being added to meet emerging needs and challenges. IoT devices usually have low computing power, making them ideal for designing numerous and complex smart devices [13]. This limited computation exposes them to compromises and threats of DoS and other attacks. These pose unusual challenges for IDS in safeguarding IoT and CPS from attacks. Therefore, IDS must be practical and nimble enough to correctly identify cyber anomalies and appropriately classify different attacks on the network [13].

Despite the effectiveness and successes of Machine Learning (ML) and Artificial Intelligence (AI) models in designing IDS for traffic attack detection of IoT and CPS, such models are still vastly regarded as black-box models. Understanding the mathematical concept that undergirds such models notwithstanding, they lack clear declarative knowledge representation [10]. This lack of knowledge, coupled with the absence of human involvement in the decisions of AI/ML models, has made the need for the explainability of ML/AI models imperative.

Explainable AI (XAI) is a series of processes and methods establishing the rationale behind the ML algorithms' working mechanism and output. XAI has become a rapidly growing ML/AI research field [3]. XAI is essential in cybersecurity as it reconciles discrepancies and gaps in our knowledge of the cyber systems and the outputs of its predictions [12]. It is important that ML/AI algorithms make decisions that are interpretable, understandable, and explainable. The availability of enormous data for training AI models does not guarantee that a particular dataset is appropriate for tackling a cybersecurity challenge. If a dataset inherently contains bias, then the trained model using this dataset will also be biased [24]. It is therefore essential to safeguard against bias in AI. Feature selection can help make a model more explainable. Feature selection helps to uncover noisy features, and removing such features reduces overfitting, which in turn improves the model's performance. In addition, a model with fewer features is more manageable and interpretable [7].

The objectives of this work are two-fold: (1) To select a subset of features for high-dimensional datasets that give the best predictive performance, and (2)
To understand the explainability of features selected in the ML/AI prediction models.

Our contributions to this work include: (1) We compare the effectiveness of various traditional ML models in finding the model with the highest predictive performance. It is unnecessary to select features that are non-predictive for a model. Feature selection presupposes that there exist features that are significant toward prediction in the model; (2) We explore two feature selection approaches, feature importance, and permutation importance, to select the best-contributing features. We then compute performance metrics on the selected features to see the improvement in terms of accuracy and time, and (3) We explain the decisions of the ML/AI model both at the individual observation (local) level and the collective dataset (global) level. This explanation will help increase the model's reliability and will help discover when adjustments may be necessary for the training of the model.

Section 2 discusses the feature selection techniques and explainable AI tools. In Sect. 3, we introduce the two datasets and describe data preprocessing. Section 4 presents the results of the analysis along with a discussion. Last, we provide our study's conclusions and propose future research directions in Sect. 5.

# 2 Description of Methodology

## 2.1 Permutation Importance and Feature Selection

Permutation feature importance is the increase in the prediction error of a model after a feature's values have been randomly shuffled [17]. Randomly shuffling the values of a feature breaks the relationship between the feature and the true outcome. Based on the permutation feature importance for a Random Forest in [5], Fisher et al. [8] proposed a model-agnostic alternative to feature importance. Motivated by [5], the algorithm for the permutation feature importance used in this work is shown below.

### Permutation Feature Algorithm

1. Input: Trained model $\hat{f}$, feature matrix $X$, performance score $m$

2. For each feature $j$ (columns of $X$):

(a) For each repetition $k$ in 1, ..., $K$:

i. Shuffle column $j$ of matrix $X$ randomly which produce an altered feature matrix $\hat{X}_{k,j}$

ii. Calculate the metrics (e.g., accuracy score), $m_{k,j}$ of model $\hat{f}$ on the altered data $\hat{X}_{k,j}$

(b) Calculate the permutation importance, $permImp_j$, for feature $j$ as:

$$ permImp_j = m - \frac{1}{K} \sum_{k=1}^{K} m_{k,j} $$

3. Output: Sort the $permImp$ importance in a descending order.
We employ Algorithm 1 to select a set of important features in the training data. Before we apply this algorithm, we first create two random features, one categorical and one numerical, called random_cat and random_num, and add them to the original feature matrix X to yield a new feature matrix X_{ wrf } (with random feature). Algorithm 1 is now applied to the X_{ wrf } dataset. Since these two random features have no prediction power in an ML model, any other features ranked below them do not contribute to prediction, so we can remove those insignificant features.

## 2.2 Explainable AI Tools

There are two broadly used techniques for explaining ML models: intrinsic (or ante-hoc) and post-hoc explanations. Ante-hoc systems are interpretable by design toward glass-box approaches [11]. These systems are inherently explainable and are model-specific. Some examples include linear regression and decision trees. Post-hoc systems perform explainability on already constructed models, which are typically complex with high accuracy [1]. The post-hoc systems of explainability are model-agnostic such that they are not tied to a particular AI model. Two of the most popular post-hoc systems are Local Interpretable Model-Agnostic Explanations (LIME) [20] and SHapley Additive exPlanations (SHAP) [14].

**LIME.** LIME was first introduced by Ribeiro et al. (2016) [20]. LIME is designed to explain the prediction of any classifier in a way that is understandable and reliable by learning a simpler and more interpretable model around the local prediction. LIME does not provide a global explanation of an AI model; instead, it gives a local explanation that is locally faithful within the neighborhood of the prediction being explained. LIME achieves this by training a local surrogate model. LIME is also model-agnostic and can explain any existing model [1]. LIME trains an interpretable model such as linear models, decision trees, or falling rules lists [17,20]. LIME's execution speed is an advantage over SHAP, but it is also limited to local interpretation, whereas SHAP can explain the importance of features both locally and globally. Mathematically, LIME can be expressed as:

$$ \text{explanation}(x) = \arg\min_{g \in G} L(f, g, \pi_x) + \Omega(g) \quad (1) $$

where x is the instance being explained, L is the model that minimizes the loss, f is the loss being minimized, Ω regularizes the model complexity which is kept low, G the family of possible explanations and π_x is the nearness or proximity measure.

**SHAP.** SHAP aims to explain a prediction by evaluating the effect of each of the features on the prediction. SHAP was first proposed by Lundberg et al. (2017) [14] to address the inconsistency of feature importance of some classifiers,
e.g., Random Forest. SHAP enhances Shapley values. The Shapley value refers to the average marginal contribution of a feature across all possible sets [16,21]. That is, the value of a feature contribution to a prediction should be considered vis-a-vis all possible subsets. The 'Shapley values' was originally developed for a cooperative game by Lloyd Shapley [16,21-23].

To extend the measurement of the features' contribution to any model (i.e., making it agnostic), the cooperative game theory concept is employed. SHAP satisfies the properties of efficiency, symmetry, dummy, and additivity. It also fulfills the properties of local accuracy, missingness, and consistency [17]. One advantage of SHAP is that it can be used for local and global explanations. One disadvantage is the long computation time. In this paper, we applied SHAP and LIME to explain the entire dataset model's predictions and the individual sample prediction.

# 3 Datasets and Preprocessing

## 3.1 IDS Datasets

The NSL-KDD dataset is one of the most popular public data, which has been used as a benchmark dataset to facilitate the comparison of different IDS. NSL-KDD was first provided as an alternative to solve the problems in the KDD'99 dataset [25]. Those problems include numerous duplicates in the training and test sets. The NSL-KDD dataset contains 125,973 samples with 42 features and one label (target), which is the status of a cyber-attack. The number of normal traffic and malicious traffic (i.e. attacks) are approximately 67,343 and 58,630 samples, respectively. The dataset also provided a separate test dataset with 22,544 samples (9,711 normal and 12,833 attack samples) and 42 predictors. The types of attacks in this data are DoS, User to Root Attacks (U2R), R2L, and Probing Attacks.

The CCID-V1 dataset, publicly available, was generated by the researchers in [13]. The data were collected in both smart homes and intelligent lab environments. NetFlow, which dissects smart devices' network behavior, was used to monitor the network traffic while real cyberattacks were injected into the traffic. The attacks used in the creation of the dataset are Address Resolution Protocol (ARP) Poisoning, ARP Denial-of-Service (DoS), User Datagram Protocol (UDP) Flood, Hydra Bruteforce with Asterisk protocol, and SlowLoris.

The original raw data of CCID-V1 contained some instances with missing values. The ratio of the cases with missing values to the total number of observations was less than 0.5%. This made the author remove those instances, as their removal has a negligible effect on the model's performance. The resulting processed CCID-V1 datasets contain 91,665 traffic samples with 82 predictors with one label as the attack type. The distribution of the normal traffic to the malicious traffic is 47,231 to 44,434. The CCID-V1 dataset did not provide a separate test dataset, so the original dataset was split into a training set and test set to train the samples and validate, respectively. The training set was 75% of the total dataset, while the test set was 25% of the total dataset.
## 3.2 Data Preprocessing

The raw data in the NSL-KDD and CCID-V1 datasets are hardly usable as they are messy, inconsistent, and incomplete. In this raw state, the data cannot be used for modeling as they will lead to poor results. Using the Python Pandas package [15], the data were checked for feature type, missing values, and duplicates, with the duplicate values removed. We also checked the label's balance in both NSL-KDD and CCID-V1 datasets, which turned out to be fairly balanced. Scikit-Learn Pipelines [19] were used for data transformations. Data imputation of missing values and one-hot encoding were implemented on the categorical features of both datasets using pipelines. Imputation and scaling were performed on the numeric features of the two datasets with pipelines. We also checked multi-collinearities among the features and removed highly correlated features.

## 3.3 ML Models and Hyperparameter Selection

Eight models were used in this research, and they are eXtreme Gradient Boosting (XGB), Random Forest, Logistic Regression, K-Nearest Neighbour (KNN), Multi-layer Perceptron (MLP), Stochastic Gradient Descent, Naïve Bayes and Support Vector Classifier (SVC). These classifiers have parameters that need to be tuned to get optimal performance. These parameters are called hyperparameters. The classifiers perform well with the default values provided by the software packages. However, to be able to compare the performances of all the classifiers and to get the best of them, there is a need to tune the parameters for optimal values. In this research, GridSearchCV [19] was used to search for the optimal hyperparameters while using cross-validation to prevent overfitting. Some of the classifiers' hyperparameters considered include *learning_rate*, *max_depth*, *min_child_weight*, *n_estimators* for XGB [6], *max_depth*, *minSamplesSplit* for Random Forest and *C*, *penalty* for Logistic Regression.

# 4 Result and Discussion

**Performance Metrics.** Table 1 and Table 2 show the various metrics for both NSL-KDD and CCID-V1 for all eight classifiers. The assessment metrics for the datasets with the two random features included are slightly higher than the original datasets without the two random features for both NSL-KDD and CCID-V1 datasets except for *MLP* classifiers. This result indicates that there is a presence of other non-informative features in the datasets that are not useful for the classification. The *XGB* classifier outperforms the other classifiers across all metrics for both datasets except *Recall* and *F1*, where it slightly lags *MLP*. Only *MLP* is comparable to *XGB* for all the metrics, but the amount of execution time is substantially higher for *MLP*. The training time of *MLP* on the moderately complex *NSL-KDD* dataset with 42 features is 65.44 s, which is more than five times the training time for *XGB* on the same dataset. With the more complex *CCID-V1* dataset with 82 features, the difference in training
time is even more pronounced: 209.98 to 6.02 s. This disparity in training time makes *XGB* a preferred choice over *MLP* as the classification model for IDS and CPS, which require a quick response in predicting network attacks. *KNN* and *GaussianNB* have particularly short training time. This result is unsurprising, especially for *GaussianNB* which assumes independence among all the features. That assumption often fails in the real world. Despite their training time advantage, the performances of both *KNN* and *GaussianNB* lag those of *XGB*. Besides, the training time for *XGB* is reasonable enough to make it a better choice over *KNN* and *GaussianNB*.

<table><caption>**Table 1.** Prediction Metrics for NSL-KDD Dataset with and without Random Features</caption><thead><tr><th>Model</th><th>Train_Acc</th><th>Test_Acc</th><th>AUC</th><th>Precision</th><th>Recall</th><th>F1</th><th>Time(s)</th></tr></thead><tbody><tr><td colspan="8">Without Random Features</td></tr><tr><td>XGB</td><td>1.0000</td><td>0.8365</td><td>0.8530</td><td>0.9726</td><td>0.7333</td><td>0.8362</td><td>11.60</td></tr><tr><td>Random Forest</td><td>1.0000</td><td>0.7797</td><td>0.8032</td><td>0.9687</td><td>0.6334</td><td>0.7660</td><td>16.92</td></tr><tr><td>Logistic Regress</td><td>0.9898</td><td>0.8099</td><td>0.8231</td><td>0.9215</td><td>0.7281</td><td>0.8135</td><td>4.23</td></tr><tr><td>KNN</td><td>0.9993</td><td>0.8324</td><td>0.8488</td><td>0.9677</td><td>0.7299</td><td>0.8321</td><td>0.50</td></tr><tr><td>MLP</td><td>0.9993</td><td>0.8412</td><td>0.8514</td><td>0.9321</td><td>0.7776</td><td>0.8479</td><td>65.44</td></tr><tr><td>SGD</td><td>0.9893</td><td>0.8078</td><td>0.8213</td><td>0.9218</td><td>0.7238</td><td>0.8109</td><td>2.12</td></tr><tr><td>GaussianNB</td><td>0.8592</td><td>0.5661</td><td>0.6179</td><td>0.9760</td><td>0.2437</td><td>0.3901</td><td>0.80</td></tr><tr><td>SVC</td><td>0.9977</td><td>0.8357</td><td>0.8509</td><td>0.9611</td><td>0.7414</td><td>0.8371</td><td>67.98</td></tr><tr><td colspan="8">with Random Features</td></tr><tr><td>XGB</td><td>1.0000</td><td>0.8403</td><td>0.8564</td><td>0.9728</td><td>0.7401</td><td>0.8406</td><td>14.86</td></tr><tr><td>Random Forest</td><td>1.0000</td><td>0.7879</td><td>0.8104</td><td>0.9693</td><td>0.6479</td><td>0.7767</td><td>19.17</td></tr><tr><td>Logistic Regress</td><td>0.9898</td><td>0.8097</td><td>0.8229</td><td>0.9215</td><td>0.7276</td><td>0.8132</td><td>4.07</td></tr><tr><td>KNN</td><td>0.9986</td><td>0.8331</td><td>0.8495</td><td>0.9680</td><td>0.7310</td><td>0.8330</td><td>0.54</td></tr><tr><td>MLP</td><td>0.9996</td><td>0.8382</td><td>0.8488</td><td>0.9314</td><td>0.7727</td><td>0.8447</td><td>80.93</td></tr><tr><td>SGD</td><td>0.9891</td><td>0.8069</td><td>0.8206</td><td>0.9218</td><td>0.7220</td><td>0.8098</td><td>1.77</td></tr><tr><td>GaussianNB</td><td>0.8592</td><td>0.5661</td><td>0.6179</td><td>0.9760</td><td>0.2437</td><td>0.3901</td><td>0.97</td></tr><tr><td>SVC</td><td>0.9976</td><td>0.8380</td><td>0.8528</td><td>0.9607</td><td>0.7460</td><td>0.8398</td><td>90.26</td></tr></tbody></table>

**Feature Selection.** Permutation importance gives a realistic indication of usefulness in feature selection as it does not depend on the training dataset statistics [19]. In feature importance by impurity, tree-based models consider a feature important depending on the number of split points by the feature for the model to make a decision [5]. The feature importance in gradient booting also resembles that of the tree-based feature importance only that gradient boosting employs entropy, instead of impurity, in calculating the importance [9]. However, both impurity and entropy-based feature importance can inflate the importance of a
<table><caption>**Table 2.** Prediction Metrics for CCID-V1 Dataset with and without Random Features</caption><thead><tr><th>Model</th><th>Train_Acc</th><th>Test_Acc</th><th>AUC</th><th>Precision</th><th>Recall</th><th>F1</th><th>Time(s)</th></tr></thead><tbody><tr><td colspan="8">Without Random Features</td></tr><tr><td>XGB</td><td>1.0000</td><td>0.9999</td><td>0.9999</td><td>0.9999</td><td>0.9999</td><td>0.9999</td><td>6.02</td></tr><tr><td>Random Forest</td><td>1.0000</td><td>0.9992</td><td>0.9992</td><td>0.9995</td><td>0.9988</td><td>0.9991</td><td>8.11</td></tr><tr><td>Logistic Regress</td><td>0.8985</td><td>0.8980</td><td>0.8976</td><td>0.9016</td><td>0.8862</td><td>0.8939</td><td>1.99</td></tr><tr><td>KNN</td><td>0.9836</td><td>0.9764</td><td>0.9765</td><td>0.9701</td><td>0.9815</td><td>0.9758</td><td>0.39</td></tr><tr><td>MLP</td><td>0.9919</td><td>0.9907</td><td>0.9905</td><td>0.9964</td><td>0.9843</td><td>0.9904</td><td>209.98</td></tr><tr><td>SGD</td><td>0.9170</td><td>0.9159</td><td>0.9151</td><td>0.9324</td><td>0.8911</td><td>0.9113</td><td>1.63</td></tr><tr><td>GaussianNB</td><td>0.6938</td><td>0.6922</td><td>0.6827</td><td>0.9870</td><td>0.3700</td><td>0.5382</td><td>0.61</td></tr><tr><td>SVC</td><td>0.9735</td><td>0.9725</td><td>0.9722</td><td>0.9793</td><td>0.9636</td><td>0.9714</td><td>138.70</td></tr><tr><td colspan="8">With Random Features</td></tr><tr><td>XGB</td><td>1.0000</td><td>0.9999</td><td>0.9999</td><td>0.9998</td><td>0.9999</td><td>0.9999</td><td>6.52</td></tr><tr><td>Random Forest</td><td>1.0000</td><td>0.9992</td><td>0.9992</td><td>0.9995</td><td>0.9987</td><td>0.9991</td><td>8.05</td></tr><tr><td>Logistic Regress</td><td>0.8997</td><td>0.8997</td><td>0.8991</td><td>0.9097</td><td>0.8805</td><td>0.8948</td><td>2.04</td></tr><tr><td>KNN</td><td>0.9567</td><td>0.9327</td><td>0.9328</td><td>0.9262</td><td>0.9357</td><td>0.9310</td><td>0.46</td></tr><tr><td>MLP</td><td>0.9898</td><td>0.9871</td><td>0.9873</td><td>0.9805</td><td>0.9931</td><td>0.9868</td><td>136.46</td></tr><tr><td>SGD</td><td>0.9332</td><td>0.9340</td><td>0.9327</td><td>0.9725</td><td>0.8890</td><td>0.9289</td><td>1.96</td></tr><tr><td>GaussianNB</td><td>0.6938</td><td>0.6923</td><td>0.6827</td><td>0.9870</td><td>0.3701</td><td>0.5383</td><td>0.75</td></tr><tr><td>SVC</td><td>0.9734</td><td>0.9723</td><td>0.9720</td><td>0.9788</td><td>0.9637</td><td>0.9712</td><td>181.44</td></tr></tbody></table>

feature that may not have a prediction power in a test dataset, especially when a model is overfitted. The impurity-based feature importance is also biased towards a feature with high cardinality, e.g., a numeric feature. Impurity-based feature importance is calculated using the training dataset statistics, and it does not always generalize to unseen dataset [19]. On the other hand, the permutation importance method uses the decrease in evaluation metric caused by the random jumbling of the non-informative features [5]. The process renders a feature unpredictive of the target. As a result, a decrease in the model metric due to the random jumbling indicates how important a particular feature is on the target. With some non-informative columns removed for brevity, the results of the permutation importance of the XGBoost model in NSL-KDD is shown in Fig. 1. The figure shows that the importances of both random features are higher than some of the features, which could be removed in the final model.

**Explainability.** SHAP and LIME were used to explain the prediction of the XGB model. Whereas LIME is best for local interpretation, SHAP can be utilized for local and global interpretation. In Figs. 2 and 3, LIME is used to explain which features are important in predicting one observation from each of the two datasets NSL-KDD and CCID-V1. LIME shows that the model predicts an attack for an instance of the NSL-KDD data in Fig. 2 because of the indicated range of values for *src_bytes*, *service_tim*, *service IRC*, *service_private*,
<figure><img src="image_3.png" /><figcaption>Fig. 1. NSL-KDD Permutation Importance</figcaption></figure>

*service_pop_3* and *service_shell*. In Fig. 3, LIME shows that the model predicts normal traffic for an instance of the CCID-V1 data because of the range of values for *src_ip*, *dst2src_first_seen_ms*, *src2dst_fin_packets*, *src2dst_mean.ps*, and *dst2src_fin_packets*. Figure 4 shows the global explanation of the predictions on CCID datasets. It shows that *scr_ip*, *dst_ip*, *scr_port*, *bidirectional_mean.ps* are all important in predicting whether a traffic signal is an attack. This is consistent with the output of the permutation importance processes.

<figure><img src="image_4.png" /><figcaption>Fig. 2. NSL-KDD LIME Local Explanation</figcaption></figure>
<figure><img src="image_5.png" /><figcaption>Fig. 3. CCID_VI LIME Local Explanation</figcaption></figure>

<figure><img src="image_6.png" /><figcaption>Fig. 4. CCID SHAP Global Explanation</figcaption></figure>

The final metrics from the selected features are shown in Table 3. Only 20 features were finally selected for NSL-KDD from the 42 original features. Similarly, 22 features were selected from the 82 original features for the CCID-V1 dataset. From Table 3, we can see that with the NSL-KDD dataset, there is an improvement of 2.49% in the test accuracy and 2.21% in AUC. The time was reduced by over 50% from 11.60 to 4.49 s. The significant improvement for the CCID-V1 dataset is the time of execution which reduces to almost half of the initial time from 6.02 to 3.27 s. These improvements make the feature selection process ideal for the design of IDS and CPS, requiring traffic attacks to be quickly detected and promptly neutralized.

<table><caption>Table 3. The Final Metrics For NSL-KDD and CCID-V1 Datasets</caption><thead><tr><th>Dataset</th><th>Model</th><th>Train_Acc</th><th>Test_Acc</th><th>AUC</th><th>Precision</th><th>Recall</th><th>F1</th><th>Time(s)</th></tr></thead><tbody><tr><td>NSL-KDD</td><td>XGB</td><td>1.0000</td><td>0.8614</td><td>0.8751</td><td>0.9750</td><td>0.7764</td><td>0.8645</td><td>4.49</td></tr><tr><td>CCID-V1</td><td>XGB</td><td>1.0000</td><td>0.9999</td><td>0.9999</td><td>1.0000</td><td>0.9998</td><td>0.9999</td><td>3.27</td></tr></tbody></table>
# 5 Conclusion

In this paper, we compared the performances of eight different ML models on two IoT-network-based datasets. XGBoost, Random Forest, Multi-Layer Perceptron (MLP) and Support Vector Classifier (SVC) all did quite well in predicting attacks on the network traffic, but the long time MLP and SVC took to train the model subordinates them to XGBoost. With XGBoost performing the best among the models, we elicited the most important features by permuting each of the features and discovering the ones with the most impact on the accuracy score of the model. With this process, we achieved on a separate test dataset of NSLKDD an AUC score of 0.8751 with a runtime of 4.49 s as against a previous run of 0.8530 AUC in 11.60 s. Although the process did not improve the metrics for the CCID-V1 dataset much, it reduced the time to almost half, from 6.2 s to 3.27 s. We also used SHAP and LIME to explain the outcome of our predictions. SHAP was used for global explanation, while LIME was able to explain the features that were locally important. The high metric scores and low training time make our process ideal for the design of an IDS. The fewer features selected also reduce the time it will take to collect more data for future training. This work can also be extended to other Machine Learning applications with high dimensional data like customer churn prediction, credit card fraud detection, mortgage loan defaults prediction, and intelligent home applications. In the future, we plan to extend the work to multi-class classification. We will also explore deep learning instead of the fully connected multi-layer perceptron, which was considered in this project.

**Acknowledgements.** This research was funded by the National Centers of Academic Excellence in Cybersecurity Grant (H98230-21-1-0326), which is part of the National Security Agency. The views and conclusions contained herein are those of the authors and should not be interpreted as necessarily representing the official policies or endorsements, either expressed or implied, of the U.S.

# References

1. Adadi, A., Berrada, M.: Peeking inside the black-box: a survey on explainable artificial intelligence (XAI). IEEE Access **6**, 52138-52160 (2018)

2. Antunes, N., Balby, L., Figueiredo, F., Lourenco, N., Meira, W., Santos, W.: Fairness and transparency of machine learning for trustworthy cloud services. In: 2018 48th Annual IEEE/IFIP International Conference on Dependable Systems and Networks Workshops (DSN-W), pp. 188-193. IEEE (2018)

3. Arrieta, A.B., et al.: Explainable artificial intelligence (XAI): concepts, taxonomies, opportunities and challenges toward responsible ai. Inf. Fusion **58**, 82-115 (2020)

4. Atzori, L., Iera, A., Morabito, G.: The internet of things: a survey. Comput. Netw. **54**(15), 2787-2805 (2010)

5. Breiman, L.: Random forests. Mach. Learn. **45**, 5-32 (2001)

6. Chen, T., Guestrin, C.: Proceedings of the 22nd ACM SIGKDD International Conference on Knowledge Discovery and Data Mining (2016)
7. Figueroa Barraza, J., López Droguett, E., Martins, M.R.: Towards interpretable deep learning: a feature selection framework for prognostics and health management using deep neural networks. Sensors **21**(17), 5888 (2021)

8. Fisher, A., Rudin, C., Dominici, F.: All models are wrong, but many are useful: learning a variable's importance by studying an entire class of prediction models simultaneously. J. Mach. Learn. Res. **20**(177), 1-81 (2019)

9. Friedman, J.H.: Greedy function approximation: a gradient boosting machine. Ann. Stat. 1189-1232 (2001)

10. Holzinger, A., Biemann, C., Pattichis, C.S., Kell, D.B.: What do we need to build explainable ai systems for the medical domain? arXiv preprint arXiv:1712.09923 (2017)

11. Holzinger, A., Plass, M., Holzinger, K., Crisan, G.C., Pintea, C.M., Palade, V.: A glass-box interactive machine learning approach for solving np-hard problems with the human-in-the-loop. arXiv preprint arXiv:1708.01104 (2017)

12. Kumar, J.S., Patel, D.R.: A survey on internet of things: security and privacy issues. Int. J. Comput. Appl. **90**(11) (2014)

13. Liu, Z., et al.: Using embedded feature selection and CNN for classification on CCD-INID-V1-A new IoT dataset. Sensors **21**(14), 4834 (2021)

14. Lundberg, S.M., Lee, S.I.: A unified approach to interpreting model predictions. In: Advances in Neural Information Processing Systems, vol. 30 (2017)

15. McKinney, W., et al.: Data structures for statistical computing in python. In: Proceedings of the 9th Python in Science Conference, Austin, TX, vol. 445, pp. 51-56 (2010)

16. Mitchell, R., Cooper, J., Frank, E., Holmes, G.: Sampling permutations for shapley value estimation (2022)

17. Molnar, C.: Interpretable machine learning. Lulu.com (2020)

18. Morris, B.: Explainable anomaly and intrusion detection intelligence for platform information technology using dimensionality reduction and ensemble learning. In: 2019 IEEE AUTOTESTCON, pp. 1-5. IEEE (2019)

19. Pedregosa, F., et al.: Scikit-learn: machine learning in Python. J. Mach. Learn. Res. **12**, 2825-2830 (2011)

20. Ribeiro, M.T., Singh, S., Guestrin, C.: Model-agnostic interpretability of machine learning. arXiv preprint arXiv:1606.05386 (2016)

21. Serrano, R.: Cooperative games: core and shapley value. Technical report, Working Paper (2007)

22. Shapley, L.: A value for n-person games. In: Kuhn, H., Tucker, A. (eds.) Contributions to the Theory of Games II (1953)

23. Sundararajan, M., Najmi, A.: The many shapley values for model explanation. In: International Conference on Machine Learning, pp. 9269-9278. PMLR (2020)

24. Sweeney, L.: Discrimination in online ad delivery. Commun. ACM **56**(5), 44-54 (2013)

25. Tavallaee, M., Bagheri, E., Lu, W., Ghorbani, A.A.: A detailed analysis of the KDD cup 99 data set. In: 2009 IEEE Symposium on Computational Intelligence for Security and Defense Applications, pp. 1-6. IEEE (2009)