File size: 35,936 Bytes
6cd8396
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# Exam Prep β€” Explainable Intrusion Detection System (X-IDS)

This document is your **deep oral-exam prep** for the presentation. It includes:

- a full pitch for every slide,
- the concepts you must know,
- likely teacher questions,
- strong answers,
- emergency short answers if you panic,
- and the key numbers from the final notebook.

Project repo: <https://huggingface.co/cathrica/deep-learning-project>  
Updated GitHub repo: <https://github.com/sloka1c/DPL>  
Final artifact: `explainable_ids_full_pipeline.ipynb - Colab.pdf`

---

## 0. The One-Minute Summary You Must Memorize

Our project is an **Explainable Intrusion Detection System**, or **X-IDS**. The goal is not only to detect whether a network connection is normal or anomalous, but also to explain **why** the model made that decision.

We used the **NSL-KDD** intrusion detection dataset, preprocessed 41 network features, and trained three deep learning models: **MLP**, **LSTM**, and **1D-CNN**. The best model was the **LSTM**, with a weighted F1-score of **0.7800**, ROC-AUC of **0.9434**, and PR-AUC of **0.9222**.

Then we applied two post-hoc explainability methods: **SHAP** and **LIME**. SHAP showed that features like `logged_in`, `dst_host_rerror_rate`, `protocol_type`, and error-rate features were important. LIME produced different rankings, and the Spearman correlation between SHAP and LIME rankings was only **0.0714**, meaning the methods did not strongly agree.

We also evaluated explanation stability. SHAP was stable for very small perturbations, with PCC **0.6293** at epsilon **0.01**, but became unstable at larger perturbations. LIME was borderline stable with mean Spearman **0.6054**. Finally, we analyzed security implications: explanations help analysts, but if exposed carelessly, they can also leak information to attackers.

**Main conclusion:** Explainability is useful for IDS, but explanations must be evaluated for stability, faithfulness, and security risk before being trusted.

---

## 1. Key Numbers to Know by Heart

### Dataset

| Item | Value |
|---|---:|
| Dataset | NSL-KDD |
| Features | 41 |
| Categorical features | `protocol_type`, `service`, `flag` |
| Train size | 151,165 records |
| Test size | 34,394 records |
| Train distribution | 80,792 normal / 70,373 anomaly |
| Test distribution | 22,531 anomaly / 11,863 normal |
| Task | Binary classification: normal vs anomaly |

### Model Results

| Model | Parameters | Weighted F1 | ROC-AUC | PR-AUC | Time |
|---|---:|---:|---:|---:|---:|
| MLP | 52,802 | 0.7639 | 0.9231 | 0.8699 | 145.1s |
| LSTM | 52,578 | **0.7800** | **0.9434** | **0.9222** | 162.9s |
| 1D-CNN | 91,074 | 0.7579 | 0.9410 | 0.9182 | 173.1s |

### Top SHAP Features β€” Anomaly Class

| Rank | Feature | Mean SHAP |
|---:|---|---:|
| 1 | `logged_in` | 0.0950 |
| 2 | `dst_host_rerror_rate` | 0.0619 |
| 3 | `protocol_type` | 0.0573 |
| 4 | `rerror_rate` | 0.0479 |
| 5 | `dst_host_serror_rate` | 0.0427 |
| 6 | `count` | 0.0398 |
| 7 | `serror_rate` | 0.0380 |
| 8 | `dst_host_same_srv_rate` | 0.0319 |
| 9 | `same_srv_rate` | 0.0256 |
| 10 | `dst_host_srv_serror_rate` | 0.0252 |

### Top LIME Features

| Feature | Frequency |
|---|---:|
| `wrong_fragment` | 30/30 |
| `rerror_rate` | 30/30 |
| `protocol_type` | 30/30 |
| `dst_host_rerror_rate` | 30/30 |
| `num_failed_logins` | 21/30 |
| `num_shells` | 21/30 |
| `logged_in` | 18/30 |
| `root_shell` | 18/30 |
| `su_attempted` | 17/30 |
| `hot` | 17/30 |

### XAI Stability / Faithfulness

| Metric | Result |
|---|---:|
| SHAP vs LIME Spearman correlation | 0.0714 |
| SHAP PCC at epsilon 0.01 | 0.6293 β€” stable |
| SHAP PCC at epsilon 0.03 | 0.5861 β€” unstable |
| SHAP PCC at epsilon 0.05 | 0.5676 β€” unstable |
| LIME stochastic stability | 0.6054 β€” borderline stable |
| Top-3 masking confidence drop | 0.3355 |
| Top-5 masking confidence drop | 0.3592 |
| Top-10 masking confidence drop | 0.4938 |

---

## 2. Full Pitch for Each Slide

Use these as scripts. Do not read them word-for-word like a robot; use them to understand what to say.

---

### Slide 1 β€” Title: Explainable Intrusion Detection System

**Pitch:**

Good morning. Our project is called **Explainable Intrusion Detection System**, or **X-IDS**. The idea is to build a deep learning IDS that detects whether a network connection is normal or anomalous, but also gives explanations for its decisions.

In cybersecurity, a prediction alone is not enough. If a model flags a connection as malicious, the security analyst needs to know *why*. So our work combines three parts: deep learning models for detection, explainability methods like SHAP and LIME, and stability/security analysis to see whether those explanations can actually be trusted.

We implemented the full pipeline on the NSL-KDD dataset, compared MLP, LSTM, and 1D-CNN models, and then analyzed explanations, their stability, faithfulness, and possible security risks.

**What to emphasize:**

- It is not just classification.
- It is detection + explanation + trust evaluation.
- You have a full reproducible Colab pipeline.

**Possible question:** Why is your project called explainable IDS and not just IDS?

**Answer:** Because the goal is not only to predict normal/anomaly, but to explain which features influenced the prediction and evaluate if those explanations are reliable.

---

### Slide 2 β€” Motivation: IDS Accuracy Is Not Enough

**Pitch:**

Traditional IDS systems generate alerts, but modern deep learning IDS models can be hard to interpret. This is a problem because cybersecurity decisions are high-stakes. If the model produces a false positive, analysts waste time. If it produces a false negative, an attack may pass undetected.

Explainability helps analysts understand whether the alert makes sense. For example, if a connection is classified as an attack because of high error rates and suspicious login behavior, that is useful evidence. But explainability also creates a risk: if an attacker sees the explanations, they may learn which features to manipulate.

So our motivation is: can we make IDS decisions interpretable, while also checking whether those explanations are stable and safe to expose?

**Concepts to know:**

- IDS = Intrusion Detection System.
- False positive = normal traffic flagged as attack.
- False negative = attack classified as normal.
- Explainability can improve trust but may leak information.

**Possible question:** Why do analysts need explanations?

**Strong answer:** Because IDS alerts must be investigated. Explanations help analysts prioritize alerts, understand model behavior, and detect whether the model is relying on meaningful security features or spurious correlations.

---

### Slide 3 β€” Research Questions

**Pitch:**

We structured the project around five research questions.

First, can deep learning models detect intrusions on NSL-KDD with acceptable performance? Second, which features drive the anomaly predictions? Third, do SHAP and LIME agree on which features are important? Fourth, are the explanations stable when we slightly perturb the inputs or rerun stochastic methods? And fifth, from a security perspective, are the important features controllable by attackers or mostly sensor-side statistics?

This structure is important because an explainable IDS should not be judged only by accuracy. It should also be judged by interpretability, consistency, and security implications.

**Possible question:** What is your main research question?

**Answer:** The main question is: can we make deep learning IDS predictions interpretable without losing detection performance, and are the explanations stable enough to be trusted in a security context?

---

### Slide 4 β€” Dataset: NSL-KDD

**Pitch:**

We used the NSL-KDD dataset, which is a standard benchmark for intrusion detection. Each sample represents a network connection described by 41 features. These include basic connection features like duration and protocol type, content features like failed logins, and traffic statistics like error rates and destination-host counts.

The task in our final pipeline is binary classification: normal versus anomaly. The training set contains 151,165 records and the test set contains 34,394 records. An important point is that the train and test distributions are different. In training, normal traffic is slightly more common, but in the test set anomalies dominate. This creates a distribution shift and makes generalization harder.

For preprocessing, we encoded the categorical features with LabelEncoder and scaled all features to [0,1] using MinMaxScaler. Scaling is especially important because features like byte counts and error rates have very different ranges.

**Things to know:**

- NSL-KDD is an improved version of KDD Cup 99.
- It has 41 features.
- Binary labels: normal/anomaly.
- Train/test distribution shift matters.

**Possible question:** Why did you use MinMaxScaler?

**Answer:** Because the features have very different numerical ranges. Scaling to [0,1] stabilizes neural network training and makes perturbation-based explanation evaluation meaningful, because epsilon noise has the same scale across features.

**Possible question:** Why LabelEncoder and not OneHotEncoder?

**Answer:** OneHotEncoder would expand the feature space and make explanations harder to interpret. LabelEncoder preserves the original 41-feature structure, which makes SHAP and LIME outputs easier to map back to IDS features. The drawback is that it introduces artificial ordering, which we mention as a limitation.

---

### Slide 5 β€” Pipeline Overview

**Pitch:**

This slide summarizes the full pipeline. We start by loading NSL-KDD from Hugging Face. Then we encode categorical variables and scale the features. After that, we train three deep learning models: MLP, LSTM, and 1D-CNN. Then we explain predictions using SHAP and LIME. Finally, we evaluate explanation stability and perform security analysis.

The important point is that this is not just theoretical. The final notebook implements the pipeline end-to-end in Colab, using a Tesla T4 GPU, with fixed random seed 42 for reproducibility.

**Possible question:** What makes your project reproducible?

**Answer:** We use a fixed random seed, documented preprocessing, fixed model architectures and hyperparameters, and a single notebook that runs data loading, training, explanation, stability evaluation, and security analysis.

---

### Slide 6 β€” Deep Learning Models

**Pitch:**

We compared three lightweight deep learning architectures.

The first is an MLP, which is a strong baseline for tabular data. It uses fully connected layers with BatchNorm, ReLU, and Dropout.

The second is an LSTM. Normally LSTMs are used for sequences, but here we treat the 41 features as a feature sequence. This allows the model to learn dependencies between feature groups.

The third is a 1D-CNN. It treats the feature vector like a one-dimensional signal and uses convolution filters to learn local patterns between neighboring features.

All three models were trained with the same optimizer, learning rate, batch size, number of epochs, and preprocessing pipeline. This makes the comparison fair.

**Concepts to know:**

- MLP = feed-forward neural network.
- LSTM = recurrent neural network with gates for sequential dependencies.
- CNN = convolutional neural network, here applied to 1D features.
- BatchNorm stabilizes training.
- Dropout reduces overfitting.
- Adam is adaptive gradient optimization.
- CrossEntropyLoss is standard for classification.

**Possible question:** Why use LSTM on tabular features?

**Answer:** It is not a natural time sequence, but NSL-KDD features are grouped semantically: basic features, content features, time-based traffic features, and host-based traffic features. Treating them as a sequence can allow the LSTM to learn dependencies between these feature groups.

**Possible question:** Why did you include CNN?

**Answer:** A 1D-CNN can learn local patterns between neighboring features, especially in grouped rate-based features. It provides an architecture comparison with different inductive bias.

---

### Slide 7 β€” Model Performance Results

**Pitch:**

Here are the main performance results. The LSTM performed best, with weighted F1-score 0.7800, ROC-AUC 0.9434, and PR-AUC 0.9222. The MLP achieved weighted F1 0.7639, and the 1D-CNN achieved 0.7579.

The LSTM was not the fastest, but it gave the best overall performance. The MLP was fastest, and the CNN had the most parameters but did not outperform the LSTM.

This result suggests that modeling feature dependencies with the LSTM was useful for this dataset. However, the difference is not huge, so all models are reasonably comparable.

**Possible question:** Why use weighted F1 instead of accuracy?

**Answer:** Because the dataset is imbalanced and the test distribution differs from training. Weighted F1 accounts for both precision and recall per class, weighted by support. Accuracy alone can hide poor performance on the minority or important class.

**Possible question:** What is ROC-AUC?

**Answer:** ROC-AUC measures how well the model ranks positive versus negative samples across classification thresholds. A value close to 1 means strong separability.

**Possible question:** What is PR-AUC and why is it useful?

**Answer:** PR-AUC is area under the precision-recall curve. It is especially useful for imbalanced classification because it focuses on precision and recall of the positive class.

---

### Slide 8 β€” SHAP: Global Feature Importance

**Pitch:**

After training, we used SHAP to explain the MLP model. SHAP assigns each feature a contribution value, based on the idea of Shapley values from game theory. In simple terms, it estimates how much each feature contributes to the prediction.

For the anomaly class, the most important feature was `logged_in`, followed by `dst_host_rerror_rate`, `protocol_type`, `rerror_rate`, and `dst_host_serror_rate`. These features make sense for intrusion detection because login status and error rates are closely related to suspicious behavior.

This result shows that the model is not using random features; it is relying on meaningful network behavior indicators.

**Concepts to know:**

- SHAP = SHapley Additive exPlanations.
- It is based on Shapley values from cooperative game theory.
- It gives local explanations and can be aggregated into global importance.
- Mean absolute SHAP value measures average feature impact.

**Possible question:** Explain SHAP simply.

**Answer:** SHAP measures how much each feature contributes to moving the prediction away from the average prediction. Positive or negative SHAP values show whether a feature pushes the prediction toward or away from a class.

**Possible question:** Why KernelExplainer?

**Answer:** KernelExplainer is model-agnostic, so it can explain any model through input-output queries. That makes it suitable for comparing explanations consistently across different architectures.

---

### Slide 9 β€” LIME vs SHAP

**Pitch:**

We also used LIME, another post-hoc explainability method. LIME explains one prediction by creating perturbed samples around it, observing the model outputs, and fitting a simple local surrogate model.

The top LIME features included `wrong_fragment`, `rerror_rate`, `protocol_type`, and `dst_host_rerror_rate`, each appearing in 30 out of 30 explanations.

However, when we compared SHAP and LIME feature rankings, the Spearman correlation was only 0.0714, with p-value 0.8665. This means the two methods did not strongly agree.

This is an important result: explainability depends on the method. We should not blindly trust a single explanation method without checking consistency.

**Concepts to know:**

- LIME = Local Interpretable Model-Agnostic Explanations.
- LIME approximates the model locally with a simpler model.
- Spearman correlation compares ranking similarity.
- Low correlation means different feature rankings.

**Possible question:** Why do SHAP and LIME disagree?

**Answer:** They use different assumptions. SHAP estimates feature contributions using a game-theoretic approach, while LIME fits a local surrogate model based on random perturbations. Different sampling, locality definitions, and weighting can lead to different feature rankings.

**Possible question:** Which one is better?

**Answer:** Not universally. SHAP has stronger theoretical foundations and is more consistent, but can be expensive. LIME is intuitive and local but stochastic and sensitive to perturbation settings. In security-critical systems, we should compare both and evaluate stability.

---

### Slide 10 β€” Explanation Stability

**Pitch:**

An explanation should be stable: if two inputs are almost the same, their explanations should also be similar. We evaluated this by adding small bounded noise to inputs and comparing SHAP attributions using PCC, or Pearson correlation coefficient.

At epsilon 0.01, SHAP had PCC 0.6293, which is above the 0.6 threshold, so we considered it stable. But at epsilon 0.03 and 0.05, PCC dropped below 0.6, meaning explanations became unstable as perturbations increased.

For LIME, we evaluated stochastic stability by running it multiple times with different seeds and measuring Spearman correlation. The average was 0.6054, just above the threshold, so it is borderline stable.

The conclusion is that explanations are not automatically reliable. Their stability must be measured.

**Concepts to know:**

- Stability = similar inputs should have similar explanations.
- Perturbation = small change/noise added to input.
- PCC = Pearson correlation coefficient, measures linear similarity.
- SENS_MAX = maximum explanation shift under perturbations.
- Spearman correlation = similarity of rankings.

**Possible question:** Why use epsilon values 0.01, 0.03, 0.05?

**Answer:** Because features were scaled to [0,1], so these epsilons represent small bounded perturbations. They allow us to test how explanations react to increasingly larger but still controlled changes.

**Possible question:** Why threshold 0.6?

**Answer:** We used 0.6 as a practical stability threshold inspired by robustness/interpretable evaluation frameworks such as SAFARI. It indicates moderate positive agreement.

---

### Slide 11 β€” Faithfulness: Feature Masking

**Pitch:**

Stability tells us whether explanations are consistent, but faithfulness tells us whether the highlighted features actually matter to the model.

To test faithfulness, we masked the top SHAP features and measured how much the model confidence dropped. If the explanation is meaningful, removing the most important features should reduce confidence.

The results show that masking the top 3 features caused an average confidence drop of 0.3355. Masking top 5 caused 0.3592, and masking top 10 caused 0.4938. So the more important features we remove, the larger the confidence drop.

This supports that SHAP is identifying features that the model really uses.

**Possible question:** What is faithfulness?

**Answer:** Faithfulness means the explanation reflects the model's actual decision process. If a feature is marked important, changing or removing it should significantly affect the model prediction.

**Possible question:** Why does top-10 masking have a bigger drop than top-3?

**Answer:** Because more influential features are removed, so the model loses more of the information it used for the prediction.

---

### Slide 12 β€” Security Implications

**Pitch:**

Explainability has two sides. It helps defenders, but it can also help attackers.

If explanations reveal that the model relies heavily on features an attacker can manipulate, then the attacker may try to change those features to evade detection. For example, if `src_bytes` or login-related features dominate, an attacker might craft traffic to change those values.

So we analyzed the top SHAP features by manipulability. Some features are manipulable, some are partially manipulable, and some are non-manipulable sensor-side statistics. Our model relied on several non-manipulable or partially manipulable features, such as destination-host error rates and host statistics. That is better for robustness than relying only on attacker-controlled fields.

But explanations should still be access-controlled, rate-limited, and monitored because repeated explanation queries could leak model strategy.

**Concepts to know:**

- Manipulable features = attacker can directly change them.
- Non-manipulable features = computed by sensor or depend on network aggregates.
- Explanation leakage = attacker learns model behavior from explanations.
- Evasion = attacker modifies input to be classified as normal.

**Possible question:** How can explanations help attackers?

**Answer:** If an attacker sees that certain features strongly drive anomaly detection, they can try to craft traffic that changes those features while preserving malicious behavior, increasing the chance of evasion.

**Possible question:** What mitigation would you propose?

**Answer:** Limit explanation access to trusted analysts, rate-limit explanation APIs, log queries, avoid exposing raw SHAP values externally, and combine ML explanations with rule-based IDS and human review.

---

### Slide 13 β€” Limitations

**Pitch:**

There are several limitations.

First, NSL-KDD is a benchmark dataset, but real network traffic is more complex and changes over time. Second, LabelEncoder preserves interpretability but introduces artificial order for categorical features. Third, Kernel SHAP is computationally expensive, so we used sampled subsets. Fourth, LIME is stochastic, so results can vary depending on random seed and perturbation settings.

Finally, our project evaluates explainability and stability, but it is not a full adversarial robustness defense. A production IDS would require more realistic traffic, online evaluation, and adversarial testing.

**Possible question:** What would you improve if you had more time?

**Answer:** I would test on more modern datasets like CIC-IDS2017 or UNSW-NB15, use one-hot or embeddings for categorical features, evaluate multiclass attack categories, and add adversarial evasion experiments.

---

### Slide 14 β€” Conclusion

**Pitch:**

To conclude, our project shows that deep learning can be used for intrusion detection and that post-hoc explainability can reveal meaningful features behind predictions.

The LSTM achieved the best detection performance. SHAP produced interpretable global feature importance, and masking experiments supported faithfulness. However, SHAP and LIME did not strongly agree, and explanation stability decreased as perturbations increased.

So the main conclusion is: explainability is valuable, but in cybersecurity we cannot trust explanations blindly. We must evaluate their stability, faithfulness, and security risks before using them in operational decision-making.

**Good final sentence:**

Our final answer is that explainable IDS is possible, but trustworthy explainable IDS requires both accurate models and rigorous explanation evaluation.

---

### Slide 15 β€” Thank You / Questions

**Pitch:**

Thank you for listening. I am ready for your questions.

If asked to summarize again, say:

We built an explainable IDS using NSL-KDD, compared MLP, LSTM, and CNN, found that LSTM performed best, used SHAP and LIME to explain predictions, evaluated stability and faithfulness, and concluded that explanations are useful but must be controlled and validated in cybersecurity contexts.

---

## 3. Deep Concepts You Should Understand

### 3.1 Intrusion Detection System

An IDS monitors network activity and detects suspicious or malicious behavior. There are two broad types:

- **Signature-based IDS:** detects known attacks using predefined rules.
- **Anomaly-based IDS:** learns normal behavior and flags deviations.

Our project is closer to anomaly-based IDS using machine learning.

### 3.2 NSL-KDD Feature Groups

NSL-KDD features include:

1. **Basic connection features** β€” duration, protocol, service, flag, bytes.
2. **Content features** β€” login attempts, root shell, failed login, compromised count.
3. **Traffic features** β€” count, srv_count, error rates.
4. **Host-based features** β€” destination host counts and rates.

Why this matters: feature groups help interpret SHAP/LIME results.

### 3.3 Classification Metrics

#### Accuracy

Percentage of correct predictions. Can be misleading with imbalance.

#### Precision

Of everything predicted as attack, how many were actually attack?

High precision = few false alarms.

#### Recall

Of all real attacks, how many did we detect?

High recall = fewer missed attacks.

#### F1-score

Harmonic mean of precision and recall.

#### Weighted F1

F1 averaged across classes weighted by class support.

#### ROC-AUC

Measures ranking quality across thresholds using true positive rate and false positive rate.

#### PR-AUC

Precision-recall area. Very useful when data is imbalanced.

### 3.4 Why Explainability Matters in Security

In normal ML tasks, an explanation is nice to have. In security, it is more important because:

- analysts need evidence,
- models may learn shortcuts,
- false positives are expensive,
- attacks evolve,
- explanations can reveal vulnerabilities.

### 3.5 SHAP

SHAP assigns each feature a contribution value. It answers:

> How much did this feature push the prediction compared to the average prediction?

Strengths:

- theoretically grounded,
- both local and global explanations,
- consistent under certain assumptions.

Weaknesses:

- can be computationally expensive,
- depends on background samples,
- feature dependence can complicate interpretation.

### 3.6 LIME

LIME explains one prediction by:

1. perturbing the input around the instance,
2. getting model predictions for perturbations,
3. fitting a simple interpretable model locally.

Strengths:

- intuitive,
- model-agnostic,
- fast for local explanations.

Weaknesses:

- stochastic,
- sensitive to perturbation distribution,
- can be unstable.

### 3.7 Stability

An explanation is stable if similar inputs produce similar explanations.

If explanation changes drastically for tiny input changes, analysts cannot trust it.

### 3.8 Faithfulness

An explanation is faithful if it reflects what the model actually uses.

Feature masking tests this:

- remove top features,
- check if confidence drops,
- bigger drop means more faithful explanation.

### 3.9 Security of Explanations

Explanations may leak:

- important features,
- model weaknesses,
- evasion strategy.

Defenses:

- access control,
- rate limiting,
- logging,
- aggregate explanations instead of raw values,
- combine with rule-based IDS.

---

## 4. Likely Exam Questions and Strong Answers

### Q1. What is the main goal of your project?

**Answer:** The goal is to build a deep learning IDS that can detect anomalies and explain its predictions using SHAP and LIME. We also evaluate whether those explanations are stable, faithful, and safe from a security perspective.

### Q2. Why did you choose NSL-KDD?

**Answer:** NSL-KDD is a standard benchmark for intrusion detection. It is cleaner than the original KDD Cup 99 and includes 41 interpretable network features, which makes it suitable for explainability analysis.

### Q3. Why binary classification and not multiclass?

**Answer:** The final pipeline focuses on binary normal/anomaly detection because it is the core IDS problem and allows clearer evaluation of explainability. Multiclass attack classification is a natural extension.

### Q4. Why compare MLP, LSTM, and CNN?

**Answer:** They represent different inductive biases: MLP for general tabular learning, LSTM for sequential dependencies between feature groups, and 1D-CNN for local feature patterns. Comparing them shows whether architecture affects performance.

### Q5. Why did LSTM perform best?

**Answer:** The LSTM may capture dependencies between ordered feature groups in NSL-KDD, such as basic features, content features, and host-based statistics. This can improve generalization compared to treating features independently.

### Q6. Why did CNN not win even though it has more parameters?

**Answer:** More parameters do not guarantee better performance. The CNN's local convolution assumption may not match the tabular feature structure as well as the LSTM's sequential dependency modeling.

### Q7. What is SHAP?

**Answer:** SHAP is an explainability method based on Shapley values. It estimates how much each feature contributes to a prediction compared to a baseline expected prediction.

### Q8. What is LIME?

**Answer:** LIME explains individual predictions by perturbing the input, observing model outputs, and fitting a simple local surrogate model to approximate the model near that instance.

### Q9. Why did SHAP and LIME disagree?

**Answer:** They use different explanation mechanisms. SHAP is game-theoretic and estimates feature contributions, while LIME builds a local surrogate from random perturbations. Their assumptions and sampling processes differ, so rankings can differ.

### Q10. Which explanation method do you trust more?

**Answer:** I would trust SHAP more for global analysis because it has stronger theoretical grounding and was used consistently. But I would not blindly trust either method; I would compare methods and evaluate stability and faithfulness.

### Q11. What does stability mean in your project?

**Answer:** Stability means that similar inputs should produce similar explanations. We tested it by perturbing inputs slightly and measuring correlation between original and perturbed explanations.

### Q12. What is SENS_MAX?

**Answer:** SENS_MAX measures the maximum change in explanation under bounded input perturbations. Lower SENS_MAX means the explanation is less sensitive and therefore more stable.

### Q13. What is PCC?

**Answer:** PCC is Pearson correlation coefficient. We used it to measure similarity between original SHAP values and perturbed SHAP values. Higher PCC means more stable explanations.

### Q14. Why did SHAP become unstable at larger epsilon?

**Answer:** Larger perturbations change the input more significantly, so the model may rely on different feature interactions. As a result, attributions shift and PCC decreases.

### Q15. What does faithfulness mean?

**Answer:** Faithfulness means the explanation reflects the model's real decision process. If top features are truly important, masking them should reduce prediction confidence.

### Q16. What did your masking experiment show?

**Answer:** Masking top SHAP features reduced confidence. Top-10 masking caused the biggest drop, 0.4938, which supports that SHAP identified meaningful features.

### Q17. What is the security risk of explainability?

**Answer:** Explanations can reveal which features the model relies on. An attacker could use that knowledge to manipulate controllable features and evade detection.

### Q18. How can you reduce explanation leakage?

**Answer:** Restrict explanation access to trusted analysts, rate-limit explanation APIs, log queries, avoid exposing raw explanation values externally, and combine ML explanations with traditional IDS rules.

### Q19. What are manipulable and non-manipulable features?

**Answer:** Manipulable features are features an attacker can directly influence, like bytes or payload-related fields. Non-manipulable features are computed by the IDS sensor or network aggregation, like destination-host statistics.

### Q20. What is the biggest limitation of your work?

**Answer:** NSL-KDD is an old benchmark dataset and may not fully represent modern traffic. Also, LabelEncoder introduces artificial ordering, and the explanation analysis used sampled subsets due to computational cost.

### Q21. If you had more time, what would you add?

**Answer:** I would test on newer datasets like CIC-IDS2017 or UNSW-NB15, evaluate multiclass attack detection, use better categorical encodings, and test adversarial evasion attacks using the explanation outputs.

### Q22. Why is PR-AUC important here?

**Answer:** Because intrusion detection datasets are often imbalanced. PR-AUC focuses on precision and recall, making it more informative than accuracy when class distributions are uneven.

### Q23. What does a low SHAP-LIME Spearman correlation mean practically?

**Answer:** It means the two explanation methods rank features differently. Practically, analysts may receive different justifications depending on the XAI method, so explanation method choice matters.

### Q24. Did your model rely on robust features?

**Answer:** Partially yes. Several top SHAP features are host-based or sensor-side statistics, which are harder for attackers to directly manipulate. However, some features are partially manipulable, so risk remains.

### Q25. How would this work in a real SOC?

**Answer:** The model would classify traffic and provide explanations to analysts. Explanations would be shown only internally, with access control and logging. Analysts would use them as supporting evidence, not as the only decision source.

---

## 5. Emergency Answers If You Panic

### If asked: What did you do?

We built a deep learning IDS on NSL-KDD, compared MLP/LSTM/CNN, explained predictions with SHAP and LIME, and evaluated explanation stability, faithfulness, and security implications.

### If asked: Best result?

The LSTM was best: weighted F1 **0.7800**, ROC-AUC **0.9434**, PR-AUC **0.9222**.

### If asked: Main conclusion?

Explainability helps understand IDS decisions, but explanations must be checked for stability and security risk before trusting them.

### If asked: SHAP vs LIME?

SHAP and LIME disagreed strongly; Spearman correlation was only **0.0714**, so XAI methods are method-dependent.

### If asked: Stability?

SHAP was stable only for small perturbations, PCC **0.6293** at epsilon **0.01**, but unstable at larger epsilon. LIME was borderline stable at **0.6054**.

### If asked: Security risk?

Explanations can leak which features attackers should manipulate, so explanation access must be controlled and monitored.

---

## 6. Mini Glossary

| Term | Meaning |
|---|---|
| IDS | Intrusion Detection System |
| X-IDS | Explainable Intrusion Detection System |
| NSL-KDD | Benchmark dataset for network intrusion detection |
| MLP | Multi-Layer Perceptron, fully connected neural network |
| LSTM | Recurrent neural network with memory gates |
| 1D-CNN | Convolutional network over one-dimensional feature vector |
| SHAP | Feature attribution method based on Shapley values |
| LIME | Local surrogate explanation method |
| ROC-AUC | Threshold-independent ranking metric |
| PR-AUC | Precision-recall area, useful for imbalance |
| Weighted F1 | F1 averaged by class support |
| PCC | Pearson correlation coefficient |
| Spearman | Rank correlation coefficient |
| SENS_MAX | Maximum explanation sensitivity to perturbation |
| Faithfulness | Whether explanation features actually affect prediction |
| Evasion | Modifying attack traffic to avoid detection |
| Explanation leakage | Attacker learning model behavior from explanations |

---

## 7. Final Advice for the Exam

1. **Do not overclaim.** Say the model is useful, not perfect.
2. **Always connect explanations to security.** This is not generic XAI; it is XAI for IDS.
3. **Mention limitations confidently.** It makes you look serious.
4. **Use the numbers.** The teacher will trust you more if you cite exact results.
5. **If stuck, return to the main message:** performance + explainability + stability + security.

Final sentence to memorize:

> Our project shows that deep learning can detect intrusions and that SHAP/LIME can explain predictions, but in cybersecurity, explanations must be evaluated for stability, faithfulness, and leakage risk before they can be trusted.