Detecting Cybersecurity Threats by Integrating Explainable AI with SHAP Interpretability and Strategic Data Sampling
Organizations: Dept. of Digital Network and Information Security Management King Mongkut’s University of Technology North Bangkok Bangkok, Thailand
Abstract
The critical need for transparent and trustworthy machine learning in cybersecurity operations drives the development of this integrated Explainable AI (XAI) framework. Our methodology addresses three fundamental challenges in deploying AI for threat detection: handling massive datasets through Strategic Sampling Methodology that preserves class distributions while enabling efficient model development; ensuring experimental rigor via Automated Data Leakage Prevention that systematically identifies and removes contaminated features; and providing operational transparency through Integrated XAI Implementation using SHAP analysis for model-agnostic interpretability across algorithms. Applied to the CIC-IDS2017 dataset, our approach maintains detection efficacy while reducing computational overhead and delivering actionable explanations for security analysts. The framework demonstrates that explainability, computational efficiency, and experimental integrity can be simultaneously achieved, providing a robust foundation for deploying trustworthy AI systems in security operations centers where decision transparency is paramount.
Figures & tables
| Study | Sampling Strategy | Feature Selection | Explainability | Performance | Key Contribution |
|---|---|---|---|---|---|
| DistilXIDS (2026) [ 9 ] | ✓ | ✓ | ✓ | 99.61% | Efficient, lightweight transformer-based language model for real-time NIDS |
| Gaitán-Cárdenas et al. (2023) [ 13 ] | ✓ | Reported* | XAI-based IDS for cloud and IoT environments | ||
| Zhou et al. (2025) [ 17 ] | Reported* | Adaptive ensemble learning for real-time attack detection | |||
| Chen et al. (2023) [ 28 ] | ✓ | 99.80% | Hardware-accelerated real-time IDS with explainable ML | ||
| Uddin et al. (2024) [ 14 ] | ✓ | Reported* | Explainable transformer-based model for phishing detection | ||
| Ma et al. (2025) [ 10 ] | ✓ | Reported* | IoT IDS with feature selection and LLM fine-tuning |
| Class | Original | Sampled | Percentage | Attack Category |
|---|---|---|---|---|
| BENIGN | 2,359,097 | 388,808 | 82.7% | Normal Traffic |
| DoS Hulk | 231,073 | 34,620 | 7.4% | Denial of Service |
| DDoS | 128,027 | 25,588 | 5.4% | Distributed DoS |
| PortScan | 158,930 | 17,979 | 3.8% | Reconnaissance |
| DoS GoldenEye | 10,293 | 2,105 | 0.4% | DoS Variant |
| FTP-Patator | 7,938 | 1,169 | 0.2% | Brute Force |
| Validation Metric | Full Dataset | 20% Sample | Difference |
|---|---|---|---|
| Distribution Similarity | |||
| Mean Packet Length (Benign) | 145.7 | 144.9 | 0.55% |
| Mean Flow Duration (Attack) | 2.31s | 2.29s | 0.87% |
| Feature Correlation Matrix Distance | – | – | 0.012 |
| Performance Consistency | |||
| XGBoost Accuracy (Binary) | 99.88% | 99.91% | +0.03% |
| Algorithm | Split | Accuracy | F1-Macro | ROC-AUC | Training Time (s) | Prediction Speed | CV Stability |
|---|---|---|---|---|---|---|---|
| XGBoost | 60-10-30 | 99.91% | 99.72% | 1.0000 | 33.90 | 324,913 | 0.99986 ± 0.00023 |
| XGBoost | 80-10-10 | 99.92% | 99.70% | 1.0000 | 47.02 | 338,961 | 0.99994 ± 0.00005 |
| XGBoost | 40-10-50 | 99.90% | 99.60% | 0.9999 | 14.73 | 683,000 | 0.99994 ± 0.00004 |
| Random Forest | 60-10-30 | 99.87% | 99.63% | 0.9999 | 80.04 | 16,049 | 0.99975 ± 0.00026 |
| Logistic Regression | 60-10-30 | 96.34% | 74.50% | 0.9895 | 415.51 | 3,423,922 | 0.98241 ± 0.00154 |
| Method | Features | Accuracy | F1-Macro | ROC-AUC | Training Time (s) | Reduction | Performance Gain |
|---|---|---|---|---|---|---|---|
| MRMR_70% | 34 | 99.92% | 99.77% | 0.9999 | 21.47 | 30.6% | +0.05% F1 |
| Chi2_70% | 34 | 99.91% | 99.72% | 1.0000 | 12.29 | 30.6% | +0.00% F1 |
| Original | 49 | 99.91% | 99.72% | 1.0000 | 33.90 | 0% | Baseline |
| MRMR_50% | 24 | 99.89% | 99.61% | 1.0000 | 16.20 | 51.0% | -0.11% F1 |
| Chi2_50% | 24 | 99.91% | 99.72% | 1.0000 | 12.28 | 51.0% | +0.00% F1 |
| MRMR_30% | 14 | 99.72% | 98.66% | 0.9999 | 23.89 | 71.4% | -1.06% F1 |
| Metric | Performance |
|---|---|
| Accuracy | 99.92% |
| F1-Macro | 99.77% |
| F1-Weighted | 99.92% |
| Precision-Macro | 99.70% |
| Recall-Macro | 99.85% |
| ROC-AUC | 99.997% |
| Attack Class | ROC-AUC |
|---|---|
| FTP-Patator | 1.0000 |
| DDoS | 0.9999 |
| DoS Hulk | 0.9999 |
| DoS GoldenEye | 0.9999 |
| BENIGN | 0.9999 |
| PortScan | 0.9999 |
| Deployment Factor | Score | Rationale |
|---|---|---|
| Detection Accuracy | 10/10 | 99.92% overall accuracy |
| False Positive Rate | 9/10 | 0.08% misclassification rate |
| Computational Efficiency | 9/10 | 324K predictions/second |
| Model Interpretability | 10/10 | Comprehensive SHAP analysis |
| Feature Optimization | 10/10 | 30.6% reduction maintained performance |
| Generalization | 9/10 | Consistent cross-configuration performance |