Abstract
Intrusion detection systems (IDSs) are very important for protecting modern computer networks against different forms of cyber-attacks. In recent years, AI, particularly machine learning and deep learning, has improved the performance, flexibility, and responsiveness of IDS. This paper discusses existing AI-based IDS approaches in detail and introduces a new hybrid Convolutional Neural Network (CNN) and Random Forest (RF) model to enhance the performance and accuracy of the IDSs. Consequently, the proposed system manages the CICIDS-2017 benchmark dataset to achieve an accuracy of 99.7%. Moreover, using Explainable AI (XAI) approaches helps researchers understand the reasons behind the predictions made by the proposed model. Moreover, in this paper, the outcomes of the proposed model experiments are explained in tables and figures, which show the model’s performance. Finally, the paper offers recommendations for future studies to increase the safety of AI-dependent network systems.
1. Introduction
Over the past decade up to the present, security has entered nearly all fields with amazing growth rates in security in distributed systems, cloud computing, and the Internet of Things that bringing numerous advantages such as efficiency, scalability, and accessibility; they have also introduced an unprecedented wave of new cyber threats. Modern networks grow increasingly susceptible to extremely advanced intrusion attacks that exploit structural weaknesses and leverage traditional defense countermeasures. Cybersecurity for infrastructure is thus a pressing requirement for governments, organizations, and consumers. The intrusion detection system (IDS) is a critical technology for this purpose, a security system that watches, examines, and reacts day and night to malicious traffic in real time [1].
Conventional approaches include signature-based and anomaly-based approaches. Signature-based IDS rely solely on pre-defined threat signatures and are ineffective at detecting unknown or stealthy attacks. Anomaly-based systems greatly excel in the domain of never-before-seen threats but with very high false positives and colossal human tuning. This has opened the door for Artificial Intelligence to be a part of cybersecurity solutions, such as intrusion detection. Machine learning (ML) and deep learning (DL) can learn to detect subtle patterns in huge datasets and categorize them without being hand-coded. Random Forests, SVM, and KNN algorithms are highly effective in utilizing structured data as well as feature extraction [2].
With the advent of DL models like CNNs and RNNs, raw, deep hierarchical features can be learned, improving the detection and identification of known and unknown attacks. Models can be employed for learning changes in novel patterns of attack, which will render the IDS more responsive and resilient. With these benefits, new challenges in employing AI in IDS emerge. One among them is the explainability of AI models [3].
However, as deep learning models become more accurate, they often become “black boxes,” offering little explanation for their decisions. This lack of transparency is quite chilling in requesting high-risk security because transparency and accountability are required. Security researchers ought to be aware of how a system arrived at its conclusion so that they can ensure the outcome, enhance detection methodologies, and satisfy regulation. Conversely, Explainable Artificial Intelligence (XAI) has also undergone further developments that made methods to explain the AI prediction readable and consistent in the same way without performance loss. This paper proposes a hybrid model for IDS that leverages the advantages of both Convolutional Neural Networks (CNNs) and Random Forest (RF) algorithms. Random Forest is chosen for its resistance to overfitting and even has the ability to choose features, primarily in high-dimensional data [4].
CNN is used for its ability to learn deep features [5]. In the system, an effort has been made to classify all such models in one category and simultaneously give Random Forest interpretability with CNN learnability. The initial trials were performed on the CICIDS-2017 dataset, utilized as a gold standard dataset in intrusion detection research to validate the accuracy and generalizability of the constructed system. This dataset contains a highly diversified amount of network traffic with normal activity and sets of different types of attacks ranging from DoS to Brute Force, Port Scanning, Infiltration, and Botnet attacks.
Its application provides an unbiased and cumulative assessment of the IDS model. The outcome of the research is that the hybrid model has a much higher accuracy rate, 98.5%, which will produce fewer false alarms in identifying sophisticated network attacks. For user trust, operational explainability and performance evaluation in the context of this paper, feature importance plots, rule visualization based on rules, and layer-wise visualization are used to describe how the model is going through input data and creates hypotheses. Integrating such developments into real-world cybersecurity operations, complete with visualization and analysis tools, is crucial, as interpretability is as important as accuracy in these contexts. This paper makes three key contributions to the development of intelligent cybersecurity systems [6].
Artificial Intelligence-based IDSs are particularly useful because they can detect and react to any compromising tasks as quickly as they happen. In addition, these systems are able to handle new threats quickly because many traditional defenses lack the capability [7]. AI-powered IDSs are also well-suited for very large and diverse environments such as cloud services, smart grids and networks based on the IoT. By using ML and DL algorithms, detection becomes more accurate and the number of false alerts for security teams decreases. For this reason, an AI-powered IDS is an important element in the security of today’s systems [8].
This study proposes a hybrid of Convolutional Neural Network and Random Forest. The hybrid algorithm is expected to increase accuracy and reduce incorrect positives, since CNN reduces problems associated with the structure and volume of the data while Random Forest deals with sophisticated features contained in the input. Using both these models at once improves the reliability and accuracy of detecting intrusions in complex networks [9].
Advanced Persistent Threats (APTs) and Distributed Denial-of-Service (DDoS) attacks are among the modern cyber threats that traditional IDS struggle to detect or prevent. Because these systems rely on specific rules or recognized threats, some attacks using hidden flaws in ever-changing networks go unnoticed. While AI-driven IDS achieve good outcomes, they also bring about some new difficulties. Issues arise from the speed and clarity in using these models. The model might respond poorly to attacks if there are insufficient malicious examples and a large number of benign ones. The challenges listed above should be dealt with first to make IDS solutions practical, trustworthy and simpler to describe [10].
The aim of this research is to design, implement, and evaluate an AI-based IDS as an effective tool for both enterprises and IoT networks. It examines how ML and DL can adapt to rapidly evolving threats [11]. Additionally, this study aims to make sure that its AI is both easy to understand and reliable by using Explainable Artificial Intelligence (XAI). The results came from conducting experiments with current malware-related benchmark datasets, including CICIDS-2017, which feature real-life cyberattacks. For this reason, this information remains essential and can help address future challenges in cybersecurity.
2. Literature Review
The paper [12] presents a novel ML-based network intrusion detection model that is specifically made for large and imbalanced datasets. It uses Principal Component Analysis (PCA) for dimensionality reduction, Random Oversampling (RO) to address data imbalance, and Stacking Feature Embedding based on clustering results.
UNSW-NB15, CIC-IDS-2017, and CIC-IDS-2018 are three state-of-the-art benchmark datasets that are used to rigorously assess this model’s performance. The experiments demonstrate that the RF and ET models attain accuracy rates of 99.59% and 99.95%, respectively, on the UNSW-NB15 dataset. Additionally, DT, RF, and ET models achieve 99.99% accuracy on the CIC-IDS2017 dataset, while DT and RF models achieve 99.94% accuracy on the CIC-IDS2018 dataset. Significant advancements in the field of network intrusion detection are demonstrated by these performance results, which consistently surpass the state-of-the-art. This accomplishment shows how effective the recommended approach is, and it can be applied effectively to precisely monitor and detect network traffic incursions, thwarting potential threats.
In study [13], a CRNN is used to create a DL-based hybrid ID framework that predicts and classifies malicious cyberattacks in the network. In the HCRNNIDS, the CNN performs convolution to capture local features, and the RNN captures temporal features to improve the ID system’s performance and prediction. To assess the efficacy of the HCRNNIDS, experiments were conducted on publicly available ID data, specifically, the modern and realistic CSE-CIC-DS2018 data. The simulation outcomes prove that the proposed HCRNNIDS substantially outperforms current ID methodologies, attaining a high malicious attack detection rate accuracy of up to 97.75% for CSE-CIC-ID2018 data cross-validation.
An ensemble platform depending on an artificial immune system (AIS) for network IDS is described in this paper. A network IDS that analyzes the massive amount of data using KDD Cup 99 events is used to specify the types of attacks with a high accuracy ratio [14].
The paper [15] presents an innovative feature selection method for a robust intrusion detection system aimed at detecting and classifying recent DDoS attack types. Evaluating its performance on the CICDDoS2019 benchmark dataset, the model achieves a detection accuracy of 96.82%, a recall of 96.82%, a precision of 96.76%, and an F1 score of 96.50%. It also features rapid prediction times, detecting attacks in just 0.189 ms, outperforming previous methods and baseline models in DDoS classification.
3. The Proposed Method
This study follows a standard methodology by collecting data, preprocessing it, developing models, implementing them and assessing the benefits of AI in IDSs. The main objective is to form an IDS that merges machine learning and deep learning to ensure it achieves the best results.
3.1. Data Collection
This experiment is built upon the well-known and widely used CICIDS-2017 benchmark in computer security. This simulation represents traffic found in networks, with both helpful and harmful behavior present and it includes attacks such as Distributed Denial of Service (DDoS), SQL Injection, Port Scan and Brute Force. Because the data comes with detailed labels and the traffic looks realistic, it is perfect for teaching and testing AI systems. The dataset is grouped into specific data frames depending on the collected time, and they are concatenated together to enhance the analysis and computations. This dataset contains about (2,393,818 row*78 col) and can be described in Table 1 below:
Table 1.
CIC-IDS-2017 data attack types.
After collecting the specific data frames into a single unified data frame, the first few rows are inspected to get an overview of the data structure. This step gives insight into the feature columns and their respective values. Figure 1 shows the first 5 rows of the dataset.
Figure 1.
The original values of dataset for 5 rows.
3.2. Preprocessing
Data preprocessing enhances model performance of a model and helps save on computing resources. The study employs the following steps:
Load Dataset: The datasets utilized were publicly available and stored in a CSV file in pcap format. The scripts were employed to read and clean each dataset, removing null and duplicate values in preparation for subsequent analysis.
Data Encoding: This step is responsible for encoding labels in datasets. Dealing with a deep neural network means dealing with numerical values. Labels in each dataset are not numerical values, so by using the One-Hot Encoder, we encoded the label column by changing the values from benign or malicious to be represented by numerical values.
Data Normalization: Normalizing the data is a preprocessing technique used to optimize within-range characteristics. The variance of the data read from the CSV file, which has different standard deviations and means, will impact the learning efficiency. In our model, we scaled the input data using StandardScaler that exist in the scikit-learn 0.17 package, resulting in a mean of zero and a standard deviation of one.
Data Balancing: The dataset suffers from class imbalance, and this imbalance can lead to Dl and ML models being biased towards the majority class, leading to poor detection of rare attack types. For this reason, SMOTE that exist into imbalanced-learn package version 0.14.2 and is used to improve model performance by generating synthetic samples of the minority class to enhance the model’s ability to detect rare attack types.
Feature Selection: For dimensionality reduction, the study employs the PCA method. Afterward, the model can concentrate on the key features by removing those that do not provide much variation.
To address the class imbalance in CICIDS-2017, where benign samples outnumber attack samples, the study uses SMOTE. Balancing the data means the system learns more about all classes by generating new samples for underrepresented attacks, thereby increasing fairness of classification results.
Class Imbalance under Binary Configuration:
Class 0—Benign Activity Ratio: 84.92%;
Class 1—Malicious Activity Ratio: 15.08%.
Class Imbalance under Multiclass Configuration (excluding the benign class):
Class 0 ratio: 84.9229%, Class 4 ratio: 7.7447%, Class 2 ratio: 5.7359;
Class 3 ratio: 0.4609%, Class 7 ratio: 0.2657%, Class 6 ratio: 0.2413%;
Class 5 ratio: 0.2342%, Class 11 ratio: 0.1442%, Class 10 ratio: 0.0876%;
Class 12 ratio: 0.0659%, Class 1 ratio: 0.0644%, Class 14 ratio: 0.0292%;
Class 9 ratio: 0.0016%, Class 13 ratio: 0.0009%, Class 8 ratio: 0.0005%.
Figure 2 shows the distribution of malicious traffic in the dataset.
Figure 2.
The distribution of malicious traffic.
3.3. Model Design
This study suggests combining the CNN and RF classifiers to make use of both deep learning’s and decision trees’ ability to detect patterns.
The dataset was split into a training set and a test set, maintaining a ratio of 70:30. To prevent overfitting, the dataset is proportionally divided into distinct subsets for each experiment.
The CNN architecture consists of three layers: convolution2dLayer, maxPooling2dLayer and fullyConnectedLayer. The CNN hyperparameters can be summarized as follows:
The input parameters are 78 features; the number of ConvID layers is 3 to prevent overfitting; convID layer1 filters = 64 + Kernel = 3; ConvID layer2 filter2 = 32 + Kernel = 3; ConvID Layer3 Filter = 16 + kernel = 3; activation function ReLU; polling type = MaxPolling1D; DenseLayers = 2 layers (64, 32 units); dense layer activation is ReLU; output layer = 1 unit; output activation is Sigmoid; learning rate = 0.001 (initial); learning rate scheduling is (decay-rate = 0.9, decay-steps = 1000); and batch size (64). The RF model combines 100 decision trees. It pools outputs from multiple trees, which ensures better classification of selected features by making the results more stable and less susceptible to change.
3.4. Assessing and Studying Features
The modeling outcomes are displayed using graphs and tables in the final evaluation. As shown in Figure 3, a set of features selected from the CICIDS-2017 dataset, along with their importance values for intrusion detection by the hybrid model, are reported.
Figure 3.
Selected CICIDS-2017 features.
Features listed in Figure 3 were found to strongly affect the separation of benign and attack traffic. The decision of which features to include is directed by their benefit in the chosen domain and by how important they are calculated by understanding the model.
4. Results
The CNN-RF hybrid model achieved significantly better classification results compared to individual ML and DL models. The performance of the hybrid system was measured on the CICIDS-2017 data using accuracy, precision, recall and F1-score.
The pipeline used by the hybrid model, which incorporates both deep learning and machine learning, can be seen in Figure 4. At the outset, the CNN selects features and labels them accordingly. It considers all input features and ranks them based on their potential usefulness. Now that a set of features has been selected, the next RF phase can be executed.
Figure 4.
The model architecture.
The features that were chosen using a Convolutional Neural Network with three layers are then fed into RF. This series uses layers like maxPooling2dLayer, fullyConnectedLayer, and convolution2dLayer to reduce dimensionality, classify features, and learn the most important features.
Figure 5 shows the Training and validation loss for binary and multiclass classification.
Figure 5.
Training and validation loss for binary and multiclass classification: (a) loss for multiclass classification; (b) accuracy for multiclass classification; (c) loss for binary classification; (d) accuracy for binary classification.
Table 2 shows the training accuracy and loss of the hybrid CNN-RF model.
Table 2.
Evaluation criteria results.
Learning could be maintained consistently after settling on a range of 99% to 99.7% for the training accuracy. Even while the Random Forest component increased post-training classification accuracy, the CNN is likely responsible for the significant feature alteration that led to worse testing accuracy. After training was over, the CNN drastically altered the features, but Random Forest enhanced classification accuracy; this indicates a discrepancy between the two models.
5. Discussion
The model used CNN to hone the set of features and remove noise. To make the hybrid model more reliable when applied to new samples, it aims to concentrate on the most significant factors and remove unnecessary or irrelevant data. When dealing with high-dimensional situations, this phase was critical for preventing overfitting.
Despite some initial difficulties, the model was able to train to a fair level and attain satisfactory recognition performance. Learning rate scheduling, early pausing, and cross-validation are efficient training approaches that can improve performance. Convolutional Neural Networks (CNNs) are computationally expensive to start up, but they can be trained more quickly and reliably by making use of GPUs.
The model’s use of predictor importance and SHAP values made the decision-making process for each outcome clear. These methods succeeded in achieving their critical goal of establishing credibility for models used in delicate sectors by assigning a monetary value to each aspect.
6. Conclusions
The study combined the interpretability of Random Forest with the feature learning strength of CNN. After preprocessing with feature selection with a three-layer CNN, and feature training with RF, we reached the ideal combination of performance, explainability, and modularity. Area under the curve (AUC), confusion matrices, and receiver operating characteristic (ROC) curves all show that hybrid models outperform single-classifier models. Over a range of classification criteria, the aforementioned hybrid model achieves an optimal balance between sensitivity and specificity. The model’s ease of use is one of its many amazing features.
Funding
This research received no external funding.
Institutional Review Board Statement
Not applicable.
Informed Consent Statement
Not applicable.
Data Availability Statement
CICIDS-2017 dataset (available online: https://www.unb.ca/cic/datasets/index.html, accessed on 28 August 2026).
Conflicts of Interest
Khalid Lateef Khudhair Al-Mayyahi was employed by the General Company of Iraqi Ports. The author declares that the research was conducted in the absence of any commercial or financial relationships that could be construed as a potential conflict of interest.
Abbreviations
The following abbreviations are used in this manuscript:
| IDS | Intrusion Detection System |
| CNN | Convolutional Neural Network |
| RF | Random Forest |
References
- Khaleefah, A.D.; Al-Mashhadi, H.M. Methodologies, Requirements, and Challenges of Cybersecurity Frameworks: A Review. Iraqi J. Sci. 2024, 65, 468–486. [Google Scholar] [CrossRef] [Scilit]
- Khaleefah, A.D.; Al-Mashhadi, H.M. Detection of IoT Botnet Cyber Attacks Using Machine Learning. Informatica 2023, 47, 497–508. [Google Scholar] [CrossRef] [Scilit]
- Hodo, E.; Bellekens, X.; Hamilton, A.; Dubouilh, P.-L.; Iorkyase, E.; Tachtatzis, C. Threat Analysis of IoT Networks Using Artificial Neural Network Intrusion Detection System. In Proceedings of the International Symposium on Networks, Computers and Communications (ISNCC), Yasmine Hammamet, Tunisia, 11–13 May 2016. [Google Scholar]
- Nidamanuri, N.D.S. AI Techniques Applied to Network Intrusion Detection System by Using Genetic Approaches. World J. Adv. Res. Rev. 2024, 24, 1638–1649. [Google Scholar] [CrossRef] [Scilit]
- Swadi, L.A.; Al-Mashhadi, H.M. Wasserstein Conditional Generative Adversarial Networks for Class Balancing in Intrusion Detection Datasets. J. Inf. Syst. Eng. Manag. 2025, 10, 16. [Google Scholar] [CrossRef] [Scilit]
- Kanimozhi, V.; Jacob, T.P. Artificial Intelligence based Network Intrusion Detection with hyper-parameter optimization tuning on the realistic cyber dataset CSE-CIC-IDS2018 using cloud computing. ICT Express 2019, 5, 211–214. [Google Scholar] [CrossRef] [Scilit]
- Öney, M.U.; Peker, S. The Use of Artificial Neural Networks in Network Intrusion Detection: A Systematic Review. In Proceedings of the 2018 International Conference on Artificial Intelligence and Data Processing (IDAP), Malatya, Turkey, 28–30 September 2018; pp. 1–6. [Google Scholar] [CrossRef] [Scilit]
- Vegesna, V.V. Analysis of Artificial Intelligence Techniques for Network Intrusion Detection and Intrusion Prevention for Enhanced User Privacy. Asian J. Appl. Sci. Technol. 2023, 2, 315–330. [Google Scholar]
- Patil, S.; Varadarajan, V.; Mazhar, S.M.; Sahibzada, A.; Ahmed, N.; Sinha, O.; Kumar, S.; Shaw, K.; Kotecha, K. Explainable Artificial Intelligence for Intrusion Detection System. Electronics 2022, 11, 3079. [Google Scholar] [CrossRef] [Scilit]
- Hyassat, A.S.; Abu Zayed, R.E.; Al Khateeb, E.A.; Shalaldeh, A.; Abdelhamied, M.M.; Qaddara, I. Unveiling Cyber Threats: An In-Depth Study on Data Mining Techniques for Exploit Attack Detection. Eng. Proc. 2025, 104, 28. [Google Scholar] [CrossRef] [Scilit]
- Anita, E.A.; Mary, T.S.; Al-Mashhadi, M.A. A Comprehensive Review of AI-Based Intrusion Detection System. Meas. Sens. 2023, 28, 100827. [Google Scholar] [CrossRef] [Scilit]
- Alabbadi, A.; Bajaber, F. An Intrusion Detection System over the IoT Data Streams Using Explainable Artificial Intelligence (XAI). Sensors 2025, 25, 847. [Google Scholar] [CrossRef] [Scilit] [PubMed]
- Khan, M.A. HCRNNIDS: Hybrid Convolutional Recurrent Neural Network-Based Network Intrusion Detection System. Processes 2021, 9, 834. [Google Scholar] [CrossRef] [Scilit]
- Kodati, S.; Sreekanth, N.; Sarma, K.S.R.K.; Reddy, P.C.S.; Saxena, A.; Narasaiah, B.P. Ensemble Framework of Artificial Immune System Based on Network Intrusion Detection System for Network Security Sustainability. E3S Web Conf. 2023, 430, 01070. [Google Scholar] [CrossRef] [Scilit]
- Najar, A.A.; Naik, M.S. A Robust DDoS Intrusion Detection System Using Convolutional Neural Network. Comput. Electr. Eng. 2024, 117, 109277. [Google Scholar] [CrossRef] [Scilit]
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2026 by the author. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license.






