Systematically Optimized CNN-Transformer with Focal Loss for Imbalanced Intrusion Detection on NSL-KDD
Kartick Sutradhar, Ranjitha Venkatesh
Key points
From the paper's conclusion- This study presents a comprehensive pipeline for imbalanced IDS, providing methodological insights, and demonstrates that tuned Focal Loss can be a sufficient and effective strategy for class balancing.
Abstract
Intrusion Detection Systems (IDS) struggle with imbalanced datasets like NSL-KDD, especially in detecting rare R2L and U2R attacks. This work describes a systematically optimized and explainable framework using a CNN-Transformer architecture to improve performance on highly imbalanced data. We decided to use XGBoost for feature selection and Focal Loss as the main mechanism for minority class learning. We used Optuna for end-to-end hyrate=0.00042, batch size=256, and Focal Loss {\gamma}), using a thoughtful data splitting process to prevent data leakage. Critically, our ablation studies pointed out that while Focal Loss (optimally at {\gamma} = 1.5) substantially enhanced minority recall, adding oversampling methods like SMOTE caused precision degradation via over-correction. Our final model, using only tuned Focal Loss, achieved 98.73% overall accuracy on the NSL-KDD test data, with significantly balanced F1-scores of 84.63% (R2L) and 69.66% (U2R) over baseline approaches. Additionally, we performed SHAP analysis to understand model predictions, understand salient features (e.g., service http, logged in), and explain the persistent U2R precision challenge due to feature overlap. This study presents a comprehensive pipeline for imbalanced IDS, providing methodological insights, and demonstrates that tuned Focal Loss can be a sufficient and effective strategy for class balancing.
Read the paper
Discussion
Science Skim's AI key points, plus readers' public thoughts
Readers' thoughts
No reader thoughts yet.
Related papers
- Twined ensemble framework for network security: integrating Random Forest, AdaBoost, and Gradient Boosting for enhanced intrusion detectionDiscover Internet of Things · 2025
- Adaptive multi-view transformer ensemble for intrusion detection: Addressing data imbalance and enhancing attack classificationInternet of Things · 2026
- A Deterministic Comparison of Classical Machine Learning and Hybrid Deep Representation Models for Intrusion Detection on NSL-KDD and CICIDS2017Algorithms · 2025
- The Aggregate–Worst-Class Trade-Off in Feature Selection for IoT Intrusion Detection: A Multi-Objective Study on TON_IoTComputation · 2026
- Autoencoder Versus CNN-1D for Network Traffic Intrusion Detection: A Reproducible Comparative Evaluation with Per-Class Analysis on CSE-CIC-IDS2018Journal of Cybersecurity and Privacy · 2026
- Anomaly-based intrusion detection on benchmark datasets for network security: a comprehensive evaluationScientific Reports · 2026