Download as pdf or txt
Download as pdf or txt
You are on page 1of 23

Journal of Computer Virology and Hacking Techniques (2023) 19:217–239

https://doi.org/10.1007/s11416-022-00441-2

ORIGINAL PAPER

XAI for intrusion detection system: comparing explanations based on


global and local scope
Swetha Hariharan1 · R. R. Rejimol Robinson2 · Rendhir R. Prasad3 · Ciza Thomas4 · N. Balakrishnan1

Received: 6 January 2022 / Accepted: 14 June 2022 / Published online: 31 July 2022
© The Author(s), under exclusive licence to Springer-Verlag France SAS, part of Springer Nature 2022

Abstract
Intrusion Detection System is a device or software in the field of cybersecurity that has become an essential tool in computer
networks to provide a secured network environment. Machine Learning based IDS offers a self-learning solution and provides
better performance when compared to traditional IDS. As the predictive performance of IDS is based on conflicting criteria,
the underlying algorithms are becoming more complex and hence, less transparent. Explainable Artificial Intelligence is a
set of frameworks that help to develop interpretable and inclusive machine learning models. In this paper, we use Permu-
tation Importance, SHapley Additive exPlanation, Local Interpretable Model-Agnostic Explanation algorithms, Contextual
Importance and Utility algorithms, covering both global and local scope of explanation to IDSs on Random Forest, eXtreme
Gradient Boosting and Light Gradient Boosting machine learning models along with a comparison of explanations in terms
of accuracy, consistency and stability. This comparison can help cyber security personnel to have a better understanding of the
predictions of cyber-attacks in the network traffic. A case study focusing on DoS attack variants shows some useful insights
on the impact of features in prediction performance.

Keywords Intrusion detection system · RF · XGBoost · LightGBM · XAI · SHAP · LIME · Permutation importance ·
Contextual importance and utility

1 Introduction

The Internet on which we heavily depend for almost every-


thing is prone to various network-based attacks. Among the
B Ciza Thomas various systems designed to counter these attacks, Intrusion
cizathomas@gmail.com Detection Systems (IDS) aid the network by providing a
Swetha Hariharan second layer of defence against both external and internal
swethahariharan1810@gmail.com attacks. Accuracy is the key indicator of intrusion detection,
R. R. Rejimol Robinson while nuisance alerts or misdetection completely undermine
ashniya@gmail.com the security of the system [1]. Machine Learning (ML) algo-
Rendhir R. Prasad rithms used in IDSs identify the patterns present in network
rendhirrprasad@gmail.com traffic and detect anomalies as attacks. The broad categories
N. Balakrishnan of supervised and unsupervised algorithms comprise of Arti-
balki@iisc.ac.in ficial Neural Networks, SVM, Decision Trees, K-Nearest
neighbour, Random Forest (RF), eXtreme Gradient Boosting
1 Supercomputer Education and Research Center, Indian (XGBoost), Light Gradient Boosting Machine (Light GBM),
Institute of Science, Bangalore, Karnataka, India
Deep Learning (DL) etc., and K-Means clustering algorithms
2 SCT College of Engineering, Thiruvananthapuram, Kerala, respectively. These machine intelligence can categorize traf-
India
fic into normal traffic and attack traffic. Modern IDSs are
3 Government Engineering College, Barton Hill, equipped with deep learning (DL) techniques that learn from
Thiruvananthapuram, Kerala, India
patterns and discover novel attack patterns present in the net-
4 Directorate of Technical Education, Government of Kerala, work traffic.
Thiruvananthapuram, Kerala, India

123
218 S. Hariharan et al.

models. Figure 1 represents the overview of the scope of


explainability methods used on these models.
Permutation Importance (PI), SHapley Additive exPlana-
tion (SHAP), Local Interpretable Model-Agnostic Explana-
tion (LIME), and Contextual Importance and Utility algo-
rithms CIU) are employed to establish the transparency of
the model as desired by the system analysts. These explain-
able methods can be compared based on certain measures
namely, accuracy, consistency and stability. Accuracy deter-
mines how well an explanation can predict unseen data.
Explanations that differ between models can be captured by
consistency measures. Stability can point out how similar are
the explanations for similar samples. The Global explanation
provides feature importance, using which predictive accu-
Fig. 1 Overview of the scope of explainability methods
racy of the explanation is compared. The local explanation is
evaluated for consistency by comparing explanations of sim-
ilar instances for two different models to indicate whether
The complex machine learning models like RF, XGBoost, the models are stable or not.
Light GBM, and DL are observed to provide superior per- This paper addresses the following research questions:
formance over the traditional ML techniques. The more
sophisticated the system is, the more is the complexity, and • How can the decisions taken by high performing tree-
complex systems are less interpretative. These models are based or tree boosting ML algorithms be explained using
referred to as “black box” in ML, as even their designers the appropriate XAI methods?
cannot explain why the AI arrived at a specific decision. • How can the different XAI methods be compared and
The underlying mathematical principles of such a model lack bench marked using various criteria?
explicit declarative knowledge. We want to understand how
decisions are being made so that we can trust the decisions Accordingly, the research contributions of this paper are as
made by these critical AI systems. However, there is always follows:
a trade-off between predictive performance and transparency
of the systems [2]. • Explainable AI methods are used to explain the deci-
The workshop titled “Implications of artificial intelli- sions made by the tree-based classifier models of Random
gence for Cybersecurity” explores certain issues, significant forest and tree boosting algorithms of extreme gradient
concerns, and interests, among policymakers, security prac- boosting and light gradient boosting algorithms which are
titioners, technologists, researchers, and the public about the applied on security data sets of NSL-KDD and Kaggle.
potential implications of AI and ML for cybersecurity [3]. • Compared and benchmarked the current and popular
The workshop concludes that the machine learning algo- model-agnostic explanation methods from both global
rithms that are applied presently can address only isolated and local scope.
characteristics of network security. In addition, it brings • Global Model Agnostic explanation methods of Permu-
out the necessity for transparent and trustworthy systems. tation Importance and SHapley Additive exPlanation are
Explainable Artificial Intelligence (XAI) is an emerging field examined to obtain interpretability of prediction, specif-
that gives importance to machine learning explainability. ically from tree-based classifier model.
In this work, we build models like RF, XGBoost, and • Local Model Agnostic methods of Local Interpretable
LightGBM for detecting anomalous activity in the network Model-Agnostic Explanation (LIME) and Contextual
traffic, with high prediction accuracy. Along with the intru- Importance and Utility algorithms (CIU) methods are
sion detection, it is necessary to provide explanations as used to obtain interpretability of prediction specifically
to what influences the decision in the cybersecurity con- from tree-based classifier model.
text. This work is intended to solve the issues of ambiguity • A case study is done with NSL-KDD DoS attack variants
in network intrusion detection by additionally providing an and studied the impact of features in prediction perfor-
explainer framework that can be implemented to explain the mance.
predictions given by these less interpretive models. All the • Investigated the algorithms and illustrated the efficiency
methods implemented in this work improve the explainabil- and quality of explanation provided by comparing them
ity of the models as post-hoc explainability methods. These on Global and Local scope by using accuracy, stability
methods cover local as well as global explanations of the and consistency as criteria.

123
XAI for intrusion detection system: comparing explanations based on global and local scope 219

The rest of the paper is organized as follows. Section 2 pro- supporting these black box models have become a necessity
vides the literature review; Sect. 3 provides an exploratory because of certain reasons. Explainable results ensure data-
analysis of the dataset, Sect. 4 describes the explanation driven decision-making and explainable reports facilitate in
methods used, Sect. 5 provides the details of the experiments improving the robustness of the model. Interpretability can
and discussion of results, and Sect. 6 is a case study on NSL- guarantee that only contextually correct variables infer the
KDD DoS attack variants and Sect. 7 is the discussion of output. The need for transparency in the new technology,
results obtained. Sect. 8 concludes the paper. like AI in health care, is discussed in the work of Sharma
et al. [9]. In machine learning, these black box models are
created directly from data by an algorithm. Hence, it is very
difficult to understand how variables are being combined to
2 Literature review
make predictions, even if one has a list of the input variables
[10].
In this section, a background study on the research progress in
Focus is on dependency of accuracy by selecting different
IDS-based security using artificial intelligence and machine
attack grouping options and influence of initial preprocessing
learning is undertaken. The other areas covered in this lit-
on accuracy by using Decision trees, Naive Bayes and Rule-
erature review is the Explainable AI of models built for
Based classifiers with NSL-KDD dataset [11]. Deshmukh
anomaly-based IDSs, which is vital for improving practical
and Padiya [12] describe a set of data preprocessing activ-
deployment of AI-based solutions.
ities including feature selection and discretization by using
Naive Bayes, NBTree and Hidden Naive Bayes on NSL-
2.1 AI and machine learning for IDS KDD dataset.

A variety of machine learning algorithms are experimented


in literature to demonstrate the effectiveness of the model
in detecting attacks, and these models are built on net-
work traffic data available in different formats. Some of the 2.2 Transparency of models
methodologies make use of feature selection algorithms to
reduce the complexity of the model. Preprocessing methods Transparency is one of the properties that can enable inter-
like oversampling and undersampling are also employed to pretability [13]. Model transparency heavily depends on
combat the issues of a skewed distribution of attacks and the predictive performance and transparency trade off. The
benign data. Othman et al. [4] investigate the importance of explainability of the model can be increased by imposing
information security and data analysis systems for Big Data, different constraints such as monotonicity, model size and
as the IDS has to handle huge amounts of data. Their work sparsity [14]. Even the choice of a model family like the
demonstrates intrusion detection model using support vector tree based model covering Decision Tree, Random Forest,
machine (SVM) classifier on Apache Spark Big Data plat- XGBoost etc can be considered a constraint on models that
form and the results of the experiment show that this model affects the interpretability. SHapley Additive exPlanations
has high performance, reduces the training time and is effi- (SHAP) is a model agnostic post-hoc explainablility method
cient for Big Data [4]. Security in the context of IoT is also proposed by Lundberg and Lee [15]. SHAP is based on coali-
a major concern and the work of Costa et al. is a survey of tion concept of game theory, a unified framework for value
machine learning algorithms with a focus on the detection of estimation of additive feature attributions that generalizes
intrusions [5]. several works from the literature [16]. Both model-agnostic
Hodo et al. use an Artificial Neural Network (ANN) model and more efficient model-specific variants are proposed.
to implement a threat analysis on IoT using network packet LIME [17] focuses on providing local explanations to a
traces [6]. Peng et al. propose a decision tree-based approach specific instance. Visual diagnosis of LIME explanation is
and compare the detection time of the model. The experimen- discussed in the work of Goode and Hofmann [18]. Evalua-
tal results demonstrate an effective model performance [7]. tion of interpretability based on different grounds is done in
Zhang et al. propose a model for binary classification using the work of Velez and Kim [19]. Visual explanation based on
Support Vector Machine (SVM) with some text processing dependencies of the input features is proposed in available
techniques employed based on the characterization of the literature [20–22]. AI Explainability 360 [23], a toolkit with
frequencies of the system calls executed by the privileged eight XAI algorithms, provides a complete evaluation of the
programs. 1998 DARPA BSM data set collected at MIT’s explanations. Wang et al. [24] propose a framework to pro-
Lincoln Labs were used for the experimentation [8]. vide a better understanding and transparency of NSL-KDD
The network security community is now using deep learn- dataset using SHAP XAI Method which helps cybersecurity
ing methods to combat ever-evolving attacks. Explanations experts to make good judgement.

123
220 S. Hariharan et al.

Table 1 Dataset Split of Kaggle


Dataset Classification type Total Train Test Target
and NSL-KDD dataset
Kaggle Binary 25192 20154 5038 Normal, Anomaly
NSL-KDD Binary 148517 125973 22544 Normal,Anomaly
NSL-KDD Multiclass 148517 125973 22544 Normal, DOS, Probe, R2L, U2R

Table 2 Feature description related to NSL-KDD dataset


Type Feature names

Binary features land, logged_in, root_shell, su_attempted, is_hot_login, is_guest_login


Continuous features duration, src_bytes, dst_bytes, wrong_fragment, urgent, hot, num_failed_logins, num_compromised, num_root,
num_file_creations, num_shell , num_access_files, num_outbound_cmds, count, srv_count, serror_rate, srv_serror_rate,
rerror_rate, srv_rerror_rate, same_srv_rate, diff_srv_rate, srv_diff_host_rate, dst_host_count, dst_host_srv_count,
dst_host_same_srv_rate, dst_host_diff_srv_rate, dst_host_same_src_port_rate, dst_host_srv_diff_host_rate,
dst_host_serror_rate, dst_host_srv_serror_rate, dst_host_rerror_rate, dst_host_srv_rerror_rate
Symbolic features protocol type: tcp , udp , icmp Flag:Oth , REJ, RSTO, RSTOS0, S0 .S1 . S2, S3, SF, SH Service: aol, auth, bgp, courier,
csnet_ns, ctf, daytime, discard, domain, domain_u, echo, eco_I, scr_I, efs, exec, finger, Ftp, Ftp_data , Gopher, Harvest
Hostnames. Http, Http_2784, Http_443, Http_8001, Imap4, Irc, Iso_tsap, Klogin, Kshell, Idap, Link, Login, Name,
Netbios_dgm, Netbios_ns, Netbios_ssn, Netstat, Nnsp, Nntp, Ntp_u, Pm_dump, Pop_2, Pop_3, Printer, Private, Red_I,
Mtp, Remote_job, Uucp, Uucp_path, Sql_net, Ssh, Sunrpc, Supdmp, Systat, Telnet, Tftp_u, Tim_I, Time, Whois, Smtp,
Urh_I, Urp_I, Rje, Shell, Vmnet, X11. Z39_50

3 Exploratory data analysis We have used google facets [27], an open-source visu-
alization tool, to understand and analyse datasets. Facets
Two data sets namely, the public network intrusion dataset consist of two visualization techniques:
available on the Kaggle site [25] and the NSL-KDD [26]
dataset are used for experimentation. Kaggle IDS dataset • Facet’s dive – allows exploring a set of observations in
provides a wide variety of intrusions simulated in a military the dataset
network environment. It creates an environment by simulat- • Facets Overview – provides an overview and understand-
ing US Air Force LAN and acquiring raw TCP/IP dump data. ing of the distribution of the various values across the
The LAN was blasted with multiple attacks. A connection features of the dataset.
consists of TCP packets starting and ending time duration,
source IP address and target IP address under some well- Facets helps in identifying common data issues such as
defined protocol. Each connection is classified and named unexpected feature values, features with high percentages of
either as normal or attack. NSL-KDD dataset is the bench- missing values, and features with unbalanced distribution.
mark for modern-day Internet traffic. Both Kaggle IDS and Table 3 shows the facets overview visualization of 7 con-
NSL-KDD data set contain 42 features per record, with 41 tinuous features. The number highlighted in bold indicates
of the features referring to the traffic input, and the last one possible trouble with the values, in this case, a numeric fea-
being the label. ture with a high percentage of values set to ‘0’ is highlighted.
The 41 features are classified as: 3 Symbolic features, 6 Table 4 shows the percent of attack distribution in both
Binary features, and 32 Continuous features training and test dataset. The training dataset is made up of 21
different attacks out of the 37 present in the test dataset. The
• Symbolic features: One hot encoder is used to convert attacks in the training dataset belonging to different attack
categorical values to binary. families are:
• Binary features: The binary values remain unchanged.
• Continuous features: Min-Max normalization was used • DOS: back, land, Neptune, pod, smurf, teardrop
to scale the continuous values in the [0-1] range. • Probe: ipsweep, nmap, portsweep, satan
• R2L: Spy, wareclient, ftp-write, guesspasswd, imap, mul-
Table 1 represents the splitting of Kaggle and NSL-KDD tihop, phf, warezmaster
dataset. NSL-KDD dataset is used as a binary classification • U2R: bufferflow, loadmodule, perl, rootkit
as well as a multi classification problem. After preprocessing
the input feature increased from 41 to 122 features [24] for The attacks in the test dataset belonging to different attack
multiclass recognition and the details are given in Table 2. families are:

123
XAI for intrusion detection system: comparing explanations based on global and local scope 221

Table 3 Facets overview


Numeric features (7)
visualization of seven numeric
Features Count Missing Mean Std dev Zeros Min Median Max
features
duration 126k 0% 287.14 2,604.52 92.05% 0 0 42.9k
src_bytes 126k 0% 45.6k 5.87M 39.21% 0 44 1.38B
dst_bytes 126k 0% 19.8k 4.02M 53.95% 0 0 1.31B
land 126k 0% 0 0.01 99.98% 0 0 1
wrong_fragment 126k 0% 0.02 0.25 99.13% 0 0 3
urgent 126k 0% 0 0.01 99.99% 0 0 3
hot 126k 0% 0.2 2.15 97.88% 0 0 77

Table 4 NSL-KDD attack distribution on dataset Algorithm 1: Compute Permutation Importance of fea-
Training dataset Testing dataset ture k
Class Distribution Class Distribution Require: Input: m - Trained Model, y - Target Vector, X - Feature
Matrix
Normal 67343 Normal 9711 Ensure: Estimate the original model error Ori = E(y, m(X ))
DOS 45927 DOS 7458
Probe 11656 Probe 2421 a. Generate feature matrix X per m by permuting feature K
in the data X . This breaks the association between feature k
R2L 995 R2L 2754 and true outcome y.
U2R 52 U2R 200 b. Estimate error Per m = E(Y , m(X per m ) based on the
Total 125973 Total 22544 predictions of the permuted data.
c. Calculate permutation feature importance
P I k = Per m/Ori.Alternatively, the difference can be used:
P I k = Per m − Ori. We are using P I k = Per m/Ori
• DOS: apache2, back, land, Mailbomb, Neptune, pod, pro-
Sort features by descending PI
cesstable, smurf, teardrop, udpstrom
• Probe: ipsweep, mscan, nmap, portsweep, saint, satan
• R2L: Spy, ftp-write, guesspasswd, httptunnel, imap,
multihop, named, phf, sendmail, snmpgetattack, warez-
It is based on the concept that randomly shuffling a single
master, xlock, xsnoop
column should cause a loss of accurate predictions since the
• U2R: bufferflow, loadmodule, perl, ps, rootkit, snmpguess,
resulting data no longer corresponds to the original observed
sqlattack, worm, xterm
target value. Model accuracy especially suffers if we shuffle
a column that the model depended on heavily for predic-
Correctly prepared data for processing guarantees precise tions. For stability of the results, any number from 50 to 100
and reliable results of data analysis. permutations is recommended [16].

4.2 SHapley Additive exPlanations (SHAP)


4 Explanation methods
SHAP, proposed by Lundberg and Lee [15], covers both
The scope of explanations in this work, falls under global and global and local scope of explanation based on Shapley value,
local post-hoc explanations. To obtain the global explanation a method in coalitional game theory. SHAP needs to sat-
we have used Permutation Importance and SHAP explana- isfy the Shapely properties, namely the symmetry, wherein
tion algorithms, and for local explanations, we have used features that contribute equally must get the same value,
LIME, SHAP and CIU [28]. dummy wherein the features that do not contribute to pre-
diction should get zero value, and additivity wherein the
4.1 Permutation importance (PI) features’ contribution must add up to the difference of pre-
diction and average. The algorithm for computing SHAP is
PI proposed in [16] normalizes the feature importance given as Algorithm 2:
thereby correcting the bias. Model reliance [29] is a model First, select an instance of interest x of which explanation
agnostic way of obtaining permutation importance. need to be generated, a feature j and the number of iterations
The permutation importance algorithm is given as Algo- needed K . For each iteration, a random instance t is selected
rithm 1: from the data and a random order of features is generated.

123
222 S. Hariharan et al.

Algorithm 2: Compute Shapley value of feature j [30] the model is given with variations of data. It generates a
Result:  j , Shapley value for the value of the j-th feature new dataset having perturbed samples and the corresponding
Input: Number of iterations K, instance of interest x, feature predictions of the black box model. This perturbed dataset is
index j, number of features p,data matrix X, and machine used for training the interpretable model, which is weighted
learning model g;
by the proximity of the sampled instances to the instance of
for k=1,...K do
interest. The interpretability of local surrogate models with
end
Draw random instance t from the data matrix X; constraints can be represented as given in Eq. 1.
Choose a random permutation λ of the feature values;
Order instance x :
E p(x) = arg min L( f , g, πx ) + (g) (1)
xλ = (x(1) , . . . , x( j) , . . . , x( p) ); g∈G
 Order the feature values of instance x according to the random
permutation λ
Order instance t : E p(x) is the function representing explanation of our sample
of interest x and it tries to minimise the loss L due to mean
tλ = (t(1) , . . . , t( j) , . . . , t( p) );
 Order the feature values of random instance t according
squared error. On the other hand we can say that, it measures
to the random permutation λ how close the explanation model g, is to the prediction of the
Construct two new instances: original model f , while maintaining the model complexity
(g) low. πx is the proximity measure, representing how
With feature j:
large the neighborhood around instance x is.
x+ j = (x(1) , . . . , x( j−1) , x( j) , t( j+1) , . . . , t( p) );
 New instance formed which contains the feature values of x
upto jth feature and the remaining feature values from instance t, 4.4 Contextual importance and utility (CIU)
while keeping the order of permutation
Without feature j: The Contextual Importance and Utility (CIU) algorithm com-
x− j = (x(1) , . . . , x( j−1) , t( j) , t( j+1) , . . . , t( p) ); prises of two algorithms to explain the model predictions, and
 New instance formed which contains the feature values of x its working is based on decision-making theory [30], [31].
upto ( j − 1)th feature and from jth feature copy the values from This algorithm is based on the fact that the significance of a
instance t, while keeping the order of permutation feature and its utility changes with respect to other feature
Compute marginal contribution
kj = ĝ(x+ j ) − ĝ(x− j ); values. So, the Contextual Importance (CI) approximates the
 ĝ(.) is the output of machine learning model overall importance of a feature in the current context, and
the Contextual Utility (CU) provides an estimation of how
Compute Shapley value as the average: favorable or not the current feature value is for a given output

 j (x) = K1 1K kj class. A Context C defines the input values x that describe
the current situation or instance to be explained. CI and CU
are defined as follows:
Two new feature vectors are created by combining values
of the instance of interest x and the random instance t. The max x (Ci ) − min x (Ci )
CI = (2)
instance x+ j is the instance of interest, but all feature values in AB Smax x − AB Smin x
the order after the jth feature are replaced by feature values yi − min x (Ci )
CU = (3)
from the sample t. The instance x− j is same as x+ j , but max x (Ci ) − min x (Ci )
feature j and other features in order are replaced by the value
for feature j and the values of other features in order from
the sample t. The difference in the prediction from the black • max x (Ci ) and min x (Ci ) are the highest and the lowest
box is computed and all the differences are averaged. This prediction values observed by varying the value of the
process is repeated for each and every feature, to find out its features, x
Shapley value. • AB Smax x and AB Smin x specifies the value range over
all predictions,
4.3 Local interpretable model-agnostic explanations • Ci is the context such as the feature or set of features
(LIME) being studied, where i is the prediction value.
• yi is the instance-specific prediction value.
LIME, proposed by Ribeiro et al. [17] uses a surrogate model
to provide local explanations. LIME explains a model by
inspecting the changes that happen to the predictions when The CIU algorithm is given as Algorithm 3:

123
XAI for intrusion detection system: comparing explanations based on global and local scope 223

Algorithm 3: Compute Contextual Importance and Util- Table 5 Permutation importance score using RF model on NSL-KDD
Binary classification dataset
ity [27]
Result: C I , CU Contextual Importance and Utility Weight Feature
Initialization: C is Context of the input values x, prediction value i,
data matrix K, and machine learning model g for k=1,...K do 0.0192 ± 0.0014 src_bytes
end 0.0153 ± 0.0007 Protocal_type_icmp
compute the prediction gk (x); 0.0092 ± 0.0014 logged_in
0.0081 ± 0.0006 Protocal_type_tcp
compute max x (Ci );
computemin x (Ci ); 0.0079 ± 0.0005 hot
compute AB Smax x ; 0.0071 ± 0.0008 dst_host_same_src_port_rate
compute AB Smin x ; 0.0061 ± 0.0007 srv_serror_rate
max x (Ci )−min x (Ci )
C I = AB Smax x −AB Smin x ; 0.0053 ± 0.0009 dst_bytes
yi −min x (Ci )
CU = max x (Ci )−min x (Ci ) ; 0.0051 ± 0.0006 dst_host_srv_serror_rate
0.0041 ± 0.0002 serror_rate
0.0039 ± 0.0006 dst_host_serror_rate
0.0038 ± 0.0015 dst_host_same_srv_rate
4.5 Methodology to compare explanations
0.0037 ± 0.0006 srv_count
0.0027 ± 0.0010 count
Both the global explanation methods, PI and SHAP, provide
the feature importance of all the input features. We have con- 0.0023 ± 0.0011 dst_host_srv_rerror_rate
sidered the top 15 features from the list, and compared the
accuracy by applying them to the RF model and XGBoost
model. The list of libraries used in ML algorithm and XAI methods
Both the local explanation methods, SHAP and LIME pro- are included here:
vide instance-based feature importance. For comparison of Machine Learning Algorithm:
local explanation, we are using Lipschitz continuity [32], a
robustness measure for a local explanation, by considering
• Random Forest classifier - Scikit learn
not just the single point, but also its neighbourhood. The
• XGBoost - Scikit learn
method to obtain the Lipschitz constant is given in equations
• Light Gradient Boosting - Scikit learn
4 and 5. We quantify the explanation model f in terms of its
Lipschitz constant L, Test data set X for every point xi of
interest as an optimization problem: XAI methods:
X = {xi }i=1
n denotes a sample of input.
• Permutation Importance - eli5 library
N (xi ) = {x j ∈X | xi − x j ≤} (4) • SHapley Additive exPlanations - shap python package
• Local Interpretable Model Agnostic Explanations - lime
where N (xi ) is a ball of radius  centered at xi , for every python package
xi ∈X . • Contextual Importance and Utility - Py-CIU python
library
f (xi ) − f (x j )
L̂(xi ) = argmax (5)
x j ∈N (xi )≤ xi − x j 5.1 Global interpretability

We are using Permutation Importance and SHAP to provide


5 Experiments and discussion of results a global scope of explanation of the model by obtaining the
feature importance.
The primary focus of this work is to build a classifier for Table 5 shows the top 15 important features obtained
network intrusion detection that can not only give a good by the permutation importance method on RF Model using
prediction performance but also augment the classifier model NSL-KDD dataset. The top three features are src_bytes, Pro-
with an explainer that can explain the predictions of the clas- tocol_type_icmp and logged in, as shown in the 2nd column
sifier. We are using the RF model, XGBoost and LightGBM of the table.
models on both the Kaggle IDS dataset for binary classi- Table 6 shows the top 15 important features obtained
fication and the NSL-KDD dataset for binary as well as by the permutation importance method on RF Model using
multi-class classification problem. Kaggle dataset. The top three features are dst_host_count,

123
224 S. Hariharan et al.

Table 6 Permutation importance score using RF model on Kaggle reliable technique without the need to retrain the model at
Binary classification dataset each modification of the dataset. However, it is more compu-
Weight Feature tationally expensive than the default feature importance and
permutation importance, and is known to overestimate the
0.0058 ± 0.0008 dst_host_count
importance of correlated predictors.
0.0040 ± 0.0012 dst_bytes
We have iterated the permutation ranging from 10 to 500,
0.0032 ± 0.0010 dst_host_same_src_port_rate for the three datasets individually, to obtain a stabilized top
0.0029 ± 0.0005 src_bytes 15 features, which will be used in the comparison.
0.0026 ± 0.0011 service_private Figures 2 and 3 are the SHAP summary plots on NSL-
0.0010 ± 0.0003 dst_host_diff_srv_rate KDD dataset with multiclass classification and binary clas-
0.0008 ± 0.0002 hot sification respectively, where the X-axis is marked with
0.0008 ± 0.0006 dst_host_srv_count the mean SHAP value and the Y-axis lists the features in
0.0005 ± 0.0004 count the ascending order of importance. The top 3 features for
0.0005 ± 0.0006 dst_host_same_srv_rate binary classification dataset using RF model are logged_in,
0.0005 ± 0.0004 srv_count dst_host_error_rate and dst_host_diff_srv_rate. The top 3
0.0004 ± 0.0001 service_ftp_data features for multiclass classification dataset using RF model
0.0004 ± 0.0001 num_compromised are flag_S0, dst_host_rerror_rate and logged_in.
0.0004 ± 0.0001 Protocal_type_icmp Figure 4 shows tha SHAP summary plots on Kaggle binary
0.0003 ± 0.0003 dst_host_rerror_rate classification dataset. The top 3 features using RF Model are
src_bytes, dst_bytes and flag_s0.

dst_bytes and dst_host_same_src_port_rate as shown in the


5.1.1 Comparison of PI and SHAP based feature importance
2nd column of the table.
for global interpretability
The value in each row corresponds how much model per-
formance, in this case accuracy, decreases with a random
Table 7 shows the comparison table where in the list of fea-
permutation, i.e, the mean decrease in accuracy. The permu-
tures based on their importance obtained from PI and SHAP
tation importance is calculated by repeating it with multiple
XAI methods on RF and XGBoost model, we have selected
permutations. The value after the +/- measures how perfor-
the top 15 features and measured the performance metric
mance varied from across permutations. The negative values
accuracy, precision, recall and F1-score of the model. Both
for permutation importance are when the permutations are
the models perform better using only the top 15 features from
more accurate than the real data. This happens when the fea-
the PI explanation when compared to considering all input
ture should have had importance close to 0, but randomness
features. Both the models also perform better with multiclass
caused the predictions on permuted data to be more accurate.
dataset using the top 15 features from the SHAP explanation
One such feature that we identified in NSL-KDD binary clas-
when compared to considering all the input features.
sification is dst_host_count with PI value 0.0007 ± 0.0010.
The Permutation importance algorithm is model agnostic so
it can be applied to any model. It is a reasonably efficient and

Fig. 2 SHAP Summary plot


using RF model on NSL-KDD
multi-class classification dataset

123
XAI for intrusion detection system: comparing explanations based on global and local scope 225

Fig. 3 SHAP Summary plot


using RF model on NSL-KDD
binary-class classification
dataset

Fig. 4 SHAP Summary plot


using RF model on Kaggle
binary classification dataset

Table 7 Comparison table on NSL-KDD and Kaggle dataset


Dataset used Features Accuracy Precision Recall F1-score

Kaggle dataset on RF Model All features 0.999 1 1 1


Top 15 features from PI 0.996 1 1 1
Top 15 features from SHAP 0.998 0.99 0.99 0.99
Kaggle dataset on XGBoost Model All features 0.999 1 1 1
Top 15 features from PI 0.997 1 1 1
Top 15 features from SHAP 0.996 1 1 1
NSL-KDD Binary dataset on RF Model All features 0.726 0.814 0.726 0.719
Top 15 features from PI 0.75 0.823 0.75 0.74
Top 15 features from SHAP 0.707 0.756 0.707 0.704
NSL-KDD Binary dataset on XGBoost Model All features 0.769 0.84 0.769 0.765
Top 15 features from PI 0.772 0.769 0.837 0.772
Top 15 features from SHAP 0.764 0.832 0.764 0.76
NSL-KDD Multiclass dataset on RF Model All features 0.691 0.796 0.691 0.644
Top 15 features from PI 0.736 0.745 0.736 0.689
Top 15 features from SHAP 0.691 0.693 0.691 0.645
NSL-KDD Multiclass dataset on XGBoost Model All features 0.717 0.8 0.717 0.667
Top 15 features from PI 0.745 0.823 0.745 0.704
Top 15 features from SHAP 0.741 0.814 0.741 0.701

123
226 S. Hariharan et al.

Fig. 5 SHAP waterfall plot for


misclassified instance using RF
model on NSL-KDD binary
classification dataset

5.2 Local interpretablility length of the gray bars, it equals the distance from the base
value to the output.
LIME and SHAP are used to provide a local scope of expla- LIME explanation of a correctly classified sample as
nation for any specific instance. Figure 6 shows the SHAP normal is shown in Figs. 7 and 8 for NSL-KDD and Kag-
explanation of a misclassified sample, where an attack is clas- gle dataset respectively. The feature value that contributes
sified as normal. in the prediction to be normal are shown in black. while
Figure 5 shows the SHAP explanation of a misclassified the features that contributes for predicting as an anomaly
sample, which is anomaly. It is observed that the predicted are shown in gray. In Fig. 7 service_provider, logged_in
SHAP value for an instance misclassified as anomaly in the and wrong_fragment here contributes to normal prediction
validation dataset is 0.89. Figure 6 shows the SHAP expla- and flag_S3, flag_SF and service_Idap here contributes to
nation of a correctly classified sample, which is normal. It anomaly prediction. In Fig. 8 service_pop_2, logged_in
is observed that the predicted SHAP value for an instance and dst_bytes here contributes to normal prediction and
classified as normal in the validation dataset is 0.89, whereas service_printer and count here contributes to anomaly pre-
the base value is 0.568. Feature values that cause an increase diction.
in predictions are shown in black. Their visual size shows the
magnitude of the feature’s effect. Feature values that cause a
decrease in the prediction are in gray. The biggest impact is
5.2.1 Contextual importance and utility local explanation
for features logged_in = 1. Also, the service_http value has
a meaningful effect in decreasing the prediction. It can be
This section provides explanations for a decision made by
noted that if we subtract the length of the black bars from the
a Random forest model on NSL-KDD dataset, for binary

123
XAI for intrusion detection system: comparing explanations based on global and local scope 227

Fig. 6 SHAP waterfall plot for


correctly classified normal
instance using RF model on
NSL-KDD binary classification
dataset

Fig. 7 LIME Explanation for


correctly classified normal
instance using RF model on
NSL-KDD binary classification
dataset

classification. A specific instance or group of instances can differently both the instances change with the new_impact
be taken from the dataset to represent current outcome of the feature.
model or a specific context. The Figs. 9 and 10 explain the
model based on CIU algorithm. For this particular example
5.2.2 Comparison of SHAP and LIME based on consistency
we have selected the features such as src_bytes and dst_bytes
and stability
to quantify the influence of interaction between these two
features. The two features are combined and represented as
We define consistency by comparing explanations between
a new feature called new_impact. Both the figures show how
similar instances for two different models. Figures 11

123
228 S. Hariharan et al.

Fig. 8 LIME Explanation for


correctly classified normal
instance using RF model on
Kaggle classification dataset

dat_host_srv_count features have a positive impact on the


prediction except emph service_http.
Table 8 shows how the similar instance with correct pre-
diction as normal using SHAP Interpretability method. The
features that have a positive effect on RF Model using the
SHAP explanation for prediction is 100% of the RF model
using the SHAP explanation with the positive effect on pre-
diction. The features that have a negative effect on RF Model
using the LIME explanation for the prediction is 100% of
the RF model using the SHAP explanation with the negative
effect on prediction. Table 9 shows how the same instance
with correct prediction as normal using SHAP and LIME
Fig. 9 Contextual importance of a sample predicted as normal Random Interpretability methods. The features that have a positive
Forest on NSL-KDD dataset
effect on RF Model using the LIME explanation for predic-
tion is 71% of the RF model using the SHAP explanation
with the positive effect on prediction. The features that have
a negative effect on RF Model using the LIME explana-
tion for the prediction is 75% of the RF model using the
SHAP explanation with the negative effect on prediction.
Table 10 shows how the same instance with correct predic-
tion as normal using LIME Interpretability method on RF and
XGBoost model. The features that have a positive effect using
LIME explanation on RF Model for prediction is 61% of the
LIME explanation with positive effect on prediction using
XGBoost model. The features that have a negative effect
using LIME explanation on RF Model for prediction is 50%
Fig. 10 Contextual utility of a sample predicted as normal Random of the LIME explanation with negative effect on prediction
Forest on NSL-KDD dataset
using XGBoost model.

and 12 illustrate the estimations performed for both RF


and XGBoost predictive models on test points of datasets 6 A case study on NSL-KDD DoS attack
using LIME with  = 1 and with only 100 neighbouring variants
data points. In the random forest model, service_private,
logged_in and wrong fragment have a positive effect on pre- DoS attack category is the major subset of attack present in
dictions while flag_SF has a negative effect. In the XGBoost the NSL-KDD dataset as a whole and hence it is important
model, src_bytes have a positive effect on predictions while to get the deeper understanding of predictions about DoS
service_shell has a negative effect. attacks in global as well as local perspectives. That is the
Figure 13 shows that the SHAP explanations main- reason why we have taken DoS attack as a case study for
taining stability as the logged_in, dst_hosts_error_rate, analysis. The influential features in predicting the attacks can

123
XAI for intrusion detection system: comparing explanations based on global and local scope 229

Fig. 11 NSL-KDD binary


instance LIME explanation on
random forest with L = 4.64

Fig. 12 NSL-KDD binary


instance LIME explanation on
XGBoost with L = 6.47

be better explored using global explanation based on binary tions such as LIME and CIU contribute to study the feature
and multiclass classification. The most important features importance of specific DoS attacks such as land and nep-
selected using SHAP and Permutation Importance as global tune. The security analysts can make use of the explanations
methods in-turn reduce the complexity of classification algo- to explore the relationship between the values of features and
rithms. Comparison of detection of same attack variant using specific attack types. Furthermore, analysis of explanations
two different models namely Random forest and LightGBM regarding a particular DoS attack variant in terms of stability
increases the trustworthiness of the system. Local explana-

123
230 S. Hariharan et al.

Fig. 13 NSL-KDD binary


instance SHAP explanation on
RF Model with L = 0.84

and consistency has been done to keep the trust of the end ond phase global and local explanations are generated using
users of the Internet. PI, SHAP and LIME. Then these Explanation methods are
We have formed a subset of training as well as test data set compared based on the aspect of global and local explana-
from the NSL-KDD train and test data respectively by select- tions generated. Global explanations mainly highlight the
ing the instances of normal and DoS attack variants only. feature importance of predictions caused by the correspond-
Table 11 explains the information regarding NSL-KDD DoS ing model. Hence, we use the important features recognised
attack only dataset. In the training set, 67343 connections by these methods to retrain the model and the performance
are labeled as ‘normal’and the rest of 45927 connections are metrics are evaluated. It is done for both binary and multi-
labeled as ‘DoS’attack. In the test set, 9711 connections are class classification using LightGBM and Random forest.
‘normal’and 7460 connections are ‘DoS’. Experiments are Then the local explanations generated by LIME and SHAP
done in three different phases based on the abstract diagram are compared based on consistency and stability aspects. In
shown in Fig. 1. In the first phase, two class and multi-class the third phase, we have used CIU to generate explanations
classifications are performed using Random forest and Light- as justifications that can be produced before intended clients
GBM algorithms. The performance metrics such as accuracy, who wish to know the details of predictions of DoS attacks.
precision, recall and F- measure are evaluated. In the sec-

123
XAI for intrusion detection system: comparing explanations based on global and local scope 231

The features that have a positive and negative


6.1 Comparison of SHAP and PI based on feature

impact on the prediction of the model for


importance

This example provides explanations for a decision made by


a Random forest model on NSL-KDD dataset, for binary

both the instances are same


classification. Tables 12 and 13 explain the model based on
PI algorithm. A specific instance or group of instances can
be taken from the dataset to represent current outcome of
the model or a specific context. For this particular example
we have selected above 90% of the features to be the same
Conclusion

in both cases. In the case of binary, the features at the top


are the majority extracted from packet header fields namely
‘src_bytes’, ‘protocol’, ‘flag’and ‘dst_bytes’. In the case of
multi-class, the feature ‘service’at the top comes under the
feature from header field. Almost all the other important fea-
Number of features having positive effect: 46

Top 3 feature with positive effect: logged_in,


effect:12 Number of features having No

service_http, flag _RSTOS0, flag_SF tures are host based features.


Number of features having Negative

Figures 14 and 15 are the summary plots of SHAP based


Actual Classification: normal-Model

feature importance. From Fig. 14, it is inferred that the mean


Top 3 feature with negative effect:
dst_host _srv_count, dst_host

shap value of feature, flag = 0.07 for class normal and it is


Prediction Probability:90%

0.14-0.07=0.07 for class neptune. The contribution of fea-


ture, same_srv_rate is 0.04 for class normal and around 0.06
Prediction:normal

for class neptune in terms of mean shap values. However, for


the RF model based on binary classification given in Fig. 15,
_serror_rate

the influence of feature flag is almost equal for class normal


effect:64
Instance 2

and attack and the influence of feature dst_bytes is bit greater


for predicting class attack than normal. The important fea-
tures selected in binary and multi-class cases are almost the
Table 8 Comparison of NSL-KDD instances with SHAP Explainable method using RF Model

same. For comparing the effect of global explanation based


on PI and SHAP, we have done the experiments for binary and
Top 3 feature with negative effect: service_http,
Number of features having Negative effect:12

dst_host _srv_count, dst_host _serror_rate

multi-class, employing Random forest and LightGBM using


Number of features having positive effect: 46

Top 3 feature with positive effect:logged _in,


Number of features having No effect: 64

the top 15 features. The comparison table in terms of accu-


racy, precision, recall and F1-score is given in the Table 14.
Actual Classification: normal Model

An improvement in performance is prominent in the case of


PI based explanation.
Prediction Probability:89%

flag _RSTOS0, flag _SF


Prediction:normal

6.2 Comparison of SHAP and LIME based on


Similar instances

consistency and stability


Instance 1

Stability is the factor that measures how similar are the


explanations for similar instances for a particular model. Fig-
ures 16 and 17 represent the stability criteria of comparison
for LIME explanations for Random forest and LightGBM
respectively. Two samples labeled as normal are selected
XAI methods

for comparison and the figure lists the top twelve fea-
SHAP

tures which influences the prediction of the instance as


normal. From Fig. 16 it is evident that, the feature value
wr ong_ f ragment ≤ 0.00 has large impact on the predic-
tion in both the cases. The majority of the features are same in
Ran-dom forest

both the cases that positively and nagatively impact the pre-
ML model

dictions. Figures 18 and 19 illustrate the stability of SHAP


Case 1

explanations for the Random forest and LightGBM respec-


tively.

123
232

123
Table 9 Comparison of NSL-KDD instances with SHAP and LIME Explainable method using RF Model
Case 2
ML model XAI methods Same instance Conclusion

Random forest SHAP Actual Classification: normal Model Prediction:-normal The features that have a positive
effect on RF Model using the
LIME explanation for prediction
is 71% of the RF model using the
SHAP explanation with the
positive effect on prediction.The
features that have a negative
effect on RF Model using the
LIME explanation for the
prediction is 75% of the RF
model using the SHAP
explanation with the negative
effect on prediction
Prediction Probability: 89%
Number of features having positive effect: 46 Number of features having Negative effect:12 Number of
features having No effect: 64
Top 3 features with positive effect:logged_in, dst_host_srv _count, dst_host _serror_rate
Top 3 features with negative effect: service_http, flag_RSTOS0, flag_SF
Random forest LIME Actual Classification: normal Model Prediction:-normal
Prediction Probability: 89%
Number of features having positive effect: 60 Number of features having Negative effect:48 Number of
features having No effect: 14
Top 3 feature with positive effect:service_private, logged_in, service_IRC
Top 3 feature with negative effect:flag_SF, flag_S2, service_domain_u
S. Hariharan et al.
Table 10 Comparison of NSL-KDD instances with LIME Explainable method using RF Model and XGBoost
Case 3
ML model XAI methods Same instance Conclusion

Random forest LIME Actual Classification: normal Model Prediction: normal The features that have a positive
effect using LIME explanation
on RF Model for prediction is
61% of the LIME explanation
with positive effect on prediction
using XGBoost model. The
features that have a negative
effect using LIME explanation
on RF Model for prediction is
50% of the LIME explanation
with negative effect on prediction
using XGBoost model
Prediction Probability: 89%
Number of features having positive effect: 60 Number of features having Negative effect:48 Number of
features having No effect: 14
XAI for intrusion detection system: comparing explanations based on global and local scope

Top 3 feature with positive effect:service_private, logged_in, service_IRC


Top 3 feature with negative effect: flag_SF, flag_S2, service_domain_u
XGBoost LIME Actual Classification: normal Model Prediction:-normal
Prediction Probability: 89%
Number of features having positive effect: 68 Number of features having Negative effect:44 Number of
features having No effect: 10
Top 3 feature with positive effect:flag_S2, num_shells, src_bytes
Top 3 feature with negative effect:service_nntp, flag_OTH, service_harvest

123
233
234 S. Hariharan et al.

Table 11 Description of
Type of classification Train Test Total Target
NSL-KDD DoS attack only
dataset along with encoded label Binary 113270 17171 130441 DoS: 0, normal: 1
details
Multi-class 113270 17171 130441 apache2 : 0, back: 1, land:
2, mailbomb : 3, neptune:
4, normal: 5, pod : 6,
processtable: 7, smurf: 8,
teardrop: 9, udpstorm: 10,
worm: 11

Table 12 PI of features on NSL-KDD DoS attack variants using Light- Consistency of LIME and SHAP describes, how much
GBM Binary classification explanations agree with each other regarding LightGBM
Weight Feature and Random forest. Figures 18 and 19 represent the con-
sistency in explanations for making predictions of similar
0.2220 ± 0.0038 src_bytes
instances labeled as normal. The scale here represents model
0.0321 ± 0.0011 protocol
prediction. The output value is the calculated prediction for
0.0088 ± 0.0005 serror_rate a particular instance. The base value is the value that would
0.0080 ± 0.0006 flag be predicted if we do not know any features for the current
0.0037 ± 0.0011 count output [15]. This is the mean of the predictions of test data.
0.0034 ± 0.0009 dst_bytes Features shown in gray push the prediction to higher values
0.0028 ± 0.0010 same_srv_rate but the features shown in black push the prediction to lower
0.0016 ± 0.0005 srv_count values. The width of the coloured arrows show how much
0.0012 ± 0.0008 wrong_fragment influential the feature is.
0.0005 ± 0.0002 dst_host_srv_rerror_rate In Fig. 18 the base value of prediction is around 0.6
0.0004 ± 0.0003 dst_host_srv_serr_rate and the actual prediction value is 1.19. The feature value,
0.0003 ± 0.0003 dst_host_rerror_rate diff_srv_rate=0.0 influences the prediction positively. How-
0.0002 ± 0.0005 dst_host_serror_rate ever, the feature in black, ie serror_rate=0.0 pushes the
0.0002 ± 0.0002 dst_host_same_src_port_rate prediction in opposite direction. The Fig. 19 explains the
0.0001 ± 0.0001 num_compromised model LightGBM in predicting the same instance. The fea-
tures positively impact the predictions are almost same in
both the cases. Figures 16 and 17 explain the consistency of
Table 13 PI of features on NSL-KDD DoS attack variants using Light- LIME regarding Random forest and LightGBM respectively.
GBM multi-class classification
Weight Feature

0.1378 ± 0.0034 service 6.3 CIU of LightGBM on NSL-KDD (DoS) dataset


0.1172 ± 0.0020 logged_in
0.0886 ± 0.0042 dst_host_diff_srv_rate Local explanations based on the outcome of the black-box
0.0726 ± 0.0045 diff_srv_rate
for a specific instance based on the context is very beneficial
for the network analyst to take appropriate decisions. For an
0.0565 ± 0.0033 dst_host_rerror_rate
end user, it is not required to explain the underlying logic of
0.0499 ± 0.0013 count
the entire black-box but only the reason for the outcome on
0.0485 ± 0.0046 dst_host_srv_serr_rate
a specific input instance.The CIU can deal with this kind of
0.0406 ± 0.0028 same_srv_rate
explanations. The high importance of a feature means that
0.0403 ± 0.0025 src_bytes
perturbations in that feature results in highest changes in the
0.0352 ± 0.0037 flag
prediction value while the lower contextual importance value
0.0199 ± 0.0019 srv_count
implies that changes on this feature do not affect the outcome
0.0183 ± 0.0008 dst_host_same_src_port_rate significantly.
0.0170 ± 0.0005 dst_host_srv_rerror_rate The contextual importance and utility plots of specific land
0.0146 ± 0.0012 dst_host_srv_count attacks missclassified as neptune and normal respectively are
0.0133 ± 0.0014 dst_host_serror_rate given in Figs. 20, 21, 22 and 23. The length of the bar cor-
responds to the CI value. A configurable threshold value of
CI can be taken to divide the features into ‘defavorable’and
‘favorable’ ranges and here it is taken as 0.5. Hence the bar

123
XAI for intrusion detection system: comparing explanations based on global and local scope 235

Fig. 14 SHAP summary plot of


features on NSL-KDD DoS
attack variants using Random
forest Binary classification

Fig. 15 SHAP summary plot of


features on NSL-KDD DoS
attack variants using Random
forest multi-class classification

123
236 S. Hariharan et al.

Table 14 Comparison table of performance measures of RF and LightGBM on NSL-KDD(DoS) dataset


Dataset used Features Accuracy Precision Recall F1-score

NSL-KDD(DoS) Binary dataset on RF Model All features 0.884 0.90 0.88 0.88
Top 15 features from PI 0.908 0.92 0.91 0.91
Top 15 features from SHAP 0.902 0.91 0.90 0.90
NSL-KDD(DoS) Binary dataset on LightGBM Model All features 0.90 0.91 0.90 0.90
Top 15 features from PI 0.92 0.93 0.92 0.92
Top 15 features from SHAP 0.902 0.91 0.90 0.90
NSL-KDD(DoS) Multiclass dataset on RF Model All features 0.886 0.81 0.89 0.85
Top 15 features from PI 0.894 0.81 0.89 0.85
Top 15 features from SHAP 0.893 0.81 0.89 0.85
NSL-KDD(DoS) Multiclassdataset on LightGBM Model All features 0.89 0.81 0.89 0.84
Top 15 features from PI 0.894 0.81 0.89 0.85
Top 15 features from SHAP 0.893 0.81 0.89 0.85

Fig. 16 LIME explanation of


similar instances of NSL-KDD
(DoS) dataset using Random
forest Binary classification

plots show the features, with influence above 50%. A specific “Why it is not categorised as attack?”. Figure 20 shows that
instance or group of instances can be taken from the dataset to the interdependent effects of src_bytes and dst_bytes have
represent current outcome of the model or a specific context. greater importance on the prediction. The importance of fea-
CIU can assess the effects of feature interaction. For this ture interaction between src_bytes and dst_bytes is around
particular example we have selected the features such as 54.72% and flag is 51.25% in the context of predicting land
src_bytes and dst_bytes to quantify the influence of inter- attack as neptune. The feature dst_host_srv_serror_rate has
action between these two features. The two features are an importance of 93.23% in the context of making prediction
combined and represented as a new feature called Fea- of land attack as normal.
ture_int1. Similarly the features such as wrong_fragment The contextual utility shows that the the grouped features
and num_failed_logins are selected for assessing the feature demonstrating the feature interactions, such as Feature_int
interaction and is represented as Feature_int2. This bar plot 1 and Feature_int 2 are giving nearly 100% utility in the
can answer “why this sample is categorised as normal?” or context of predicting land attack as neptune. In predicting

123
XAI for intrusion detection system: comparing explanations based on global and local scope 237

Fig. 17 LIME explanation of similar instances of NSL-KDD (DoS)


dataset using LightGBM Binary classification

Fig. 20 Contextual importance of land attack predicted as neptune

Fig. 18 SHAP explanation of of NSL-KDD (DoS) dataset using Ran-


dom forest Binary classification

Fig. 19 SHAP explanation of NSL-KDD (DoS) dataset using Light-


GBM Binary classification

land attack as normal, the CU of the feature interaction named


Feature_int 2 is around 100%.

Fig. 21 Contextual importance of land attack predicted as normal


7 Discussion
from global Permutation Importance and global SHAP inter-
In this work, we compare the different explanation frame- pretability methods and we observed that the accuracy of the
work focusing on model agnostic XAI methods covering model prediction for the top 15 features obtained using both
both global and local scope. We examine model agnostic the global XAI method on NSL-KDD dataset ranges from
global XAI methods (PI, SHAP) and model agnostic local 70% to 75% .
XAI methods (SHAP, LIME, and CIU) explanation methods For the Local comparison of explanation methods we mea-
to interpret the predictions for RF, XGBoost and LGBoost sured the robustness in terms of three cases and the findings
models. We build classifiers by using Kaggle IDS classifica- are as follows:
tion datasets and NSL-KDD IDS classification dataset. Our • Case 1: Compare similar instance using SHAP inter-
results show that for the global comparison of explanation pretability method on RF model:
methods we measured the robustness in terms of accuracy, We observed that there is 100% match in the feature that
recall and precision considering the top 15 features obtained affects the prediction positively and negatively.

123
238 S. Hariharan et al.

8 Conclusion

In this paper, we have discussed the necessity of explain-


ing the machine learning model to the end user/analyst, and
the major hurdles of presenting a trustworthy model when
analysing the performance of anomaly based IDSs. Over
the years, one of the major challenges of ML-based IDSs
is the very high rate of false positives. The sophisticated ML
algorithms employed to improve the performance in turn
increases the complexity of the model. XAI methods pro-
vide us with interpretability to prediction, which can help in
redesigning the structure of IDSs to improve performance.
In this paper we have covered both global and local scope
of explanation along with providing a comparison with the
model evaluation metrics, namely, accuracy, precision, recall
and F1 score of the top 15 features obtained from PI and
Fig. 22 Contextual utility of land attack predicted as normal
SHAP. The local explanation comparison is made based on
consistency and stability. The case study with DoS attack
variants helps to study the impact of features on model perfor-
mance, specifically for DoS attacks. It is desirable to ensure
that the explanations provided by the models are acceptable
or it meets the requirements for which it is meant for, and
this is planned to be done in detail as a future work.

References
1. Hu, X., Li, T., Wu, Z., Gao, X., Wang, Z.: Research and application
of intelligent intrusion detection system with accuracy analysis
methodology. Infrared Phys. Technol. 88, 245–253 (2018)
2. Holzinger, A.: From machine learning to explainable AI. In:
World symposium on digital intelligence for systems and machines
(DISA), pp. 55–66 (2018)
3. National Academies of Sciences, Engineering, and Medicine et al.:
Implications of artificial intelligence for cybersecurity. In: Proceed-
ings of a Workshop. National Academies Press (2019)
Fig. 23 Contextual utility of land attack predicted as normal
4. Othman, S.M., Ba-Alwi, F.M., Alsohybe, N.T., Al-Hashida, A.Y.:
Intrusion detection model using machine learning algorithm on big
data environment. J. Big Data 5(1), 1–12 (2018)
• Case 2: Compare same instance using SHAP and LIME 5. Da Costa, K.A., Papa, J.P., Lisboa, C.O., Munoz, R., de Albu-
querque, V.H.C.: Internet of things: a survey on machine learning-
interpretability method on RF model: based intrusion detection approaches. Comput. Netw. 151, 147–
We observed that there is an 71% match in the feature that 157 (2019)
affects the prediction positively and 75% match in the feature 6. Hodo, E. et al.: Threat analysis of IoT networks using artificial
that affects the prediction negatively. neural network intrusion detection system, pp. 1–6. IEEE (2016)
7. Peng, K., et al.: Intrusion detection system based on decision tree
• Case 3: Compare same instance using LIME interpretability over big data in fog environment. Wirel. Commun. Mob. Comput.
method on RF and XGBoost model: 2018 (2018)
We observed that there is an 61% match in the feature that 8. Zhang, Z., Shen, H.: Application of online-training SVMs for real-
affects the prediction positively and 50% match in the feature time intrusion detection with different considerations. Comput.
Commun. 28(12), 1428–1442 (2005)
that affects 9. Sharma, Y., Verma, A., Rao, K., Eluri, V.: Reasonable explainability
the prediction negatively. for regulating AI in health. ORF occasional paper (261) (2020)
Our future work focuses on assessing the robustness of 10. Rudin, C., Radin, J.: Why are we using black box models in ai when
explanations on models from different family and inspire we don’t need to? A lesson from an explainable AI competition.
Harvard Data Sci. Rev. 1(2) (2019)
further exploration in the same area. 11. Paulauskas, N., Auskalnis, J.: Analysis of data pre-processing influ-
ence on intrusion detection using NSL-KDD dataset. In: Open

123
XAI for intrusion detection system: comparing explanations based on global and local scope 239

Conference of Electrical, Electronic and Information Sciences 23. Arya, V., et al.: One explanation does not fit all: a toolkit
(eStream), pp. 1–5. IEEE (2017) and taxonomy of ai explainability techniques. arXiv preprint
12. Datta, H., Deshmukh, T.G., Puja Padiya, Y.: International Con- arXiv:1909.03012 (2019)
ference on Communication, Information & Computing Technol- 24. Maonan Wang, Y.Y., Kangfeng Zheng, W.X.: An explainable
ogy (ICCICT). Improving classification using preprocessing and machine learning framework for intrusion detection systems. IEEE
machine learning algorithms on NSL-KDD dataset Access 8(2020), 73127–73141 (2020)
13. Lipton, Z.: The mythos of model interpretability. arXiv preprint 25. Kaggle dataset. https://www.kaggle.com/sampadab17/network-
arXiv:1606.03490 (2016) intrusion-detection
14. Freitas, A.A.: Comprehensible classification models: a position 26. NSL-KDD data set for network-based intrusion detection systems.
paper. ACM SIGKDD Explor. Newsl. 15(1), 1–10 (2014) https://www.unb.ca/cic/datasets/nsl.html
15. Lundberg, S.M., Lee, S.-I.: A unified approach to interpreting 27. https://pair-code.github.io/facets/
model predictions, 4768–4777 (2017) 28. Carvalho, D.V., Pereira, E.M., Cardoso, J.S.: Machine learning
16. Altmann, A., Toloşi, L., Sander, O., Lengauer, T.: Permutation interpretability: a survey on methods and metrics. Electronics 8(8),
importance: a corrected feature importance measure. Bioinformat- 832 (2019)
ics 26(10), 1340–1347 (2010) 29. Fisher, A., Rudin, C., Dominici, F.: All models are wrong, but many
17. Ribeiro, M.T., Singh, S., Guestrin, C.: Why should i trust you? are useful: learning a variable’s importance by studying an entire
Explaining the predictions of any classifier, 1135–1144 (2016) class of prediction models simultaneously. J. Mach. Learn. Res.
18. Goode, K., Hofmann, H.: Visual diagnostics of an explainer model: 20(177), 1–81 (2019)
tools for the assessment of lime explanations. Stat. Anal. Data Min. 30. Anjomshoae, S., Främling, K., Najjar, A.: Explanations of Black–
ASA Data Sci. J. 14(2), 185–200 (2021) Box Model Predictions by Contextual Importance and Utility, pp.
19. Doshi-Velez, F., Kim, B.: Towards a rigorous science of inter- 95–109. Springer, New York (2019)
pretable machine learning. arXiv preprint arXiv:1702.08608 31. Främling, K.: Decision Theory Meets Explainable AI, pp. 57–74.
(2017) Springer, New York (2020)
20. Zhao, Q., Hastie, T.: Causal interpretations of black-box models. 32. Alvarez-Melis, D., Jaakkola, T.S.: On the robustness of inter-
J. Bus. Econ. Stat. 39(1), 272–281 (2021) pretability methods. arXiv preprint arXiv:1806.08049 (2018)
21. Goldstein, A., Kapelner, A., Bleich, J., Pitkin, E.: Peeking inside
the black box: visualizing statistical learning with plots of individ-
ual conditional expectation. J. Comput. Graph. Stat. 24(1), 44–65
Publisher’s Note Springer Nature remains neutral with regard to juris-
(2015)
dictional claims in published maps and institutional affiliations.
22. Apley, D.W., Zhu, J.: Visualizing the effects of predictor variables
in black box supervised learning models. J. R. Stat. Soc. Ser. B
Springer Nature or its licensor holds exclusive rights to this article
(Stat. Methodol.) 82(4), 1059–1086 (2020)
under a publishing agreement with the author(s) or other rightsholder(s);
author self-archiving of the accepted manuscript version of this article
is solely governed by the terms of such publishing agreement and appli-
cable law.

123

You might also like