Comparative Analysis of Random Forest and Artificial Neural Network Models for Network Traffic Anomaly Detection on the NSL-KDD Dataset
DOI:
https://doi.org/10.56158/jcosml.2026.1.1.1Keywords:
Anomaly detection, NSL-KDD, Random forest, Artificial neural networks, False alarm rate, Network intrusion detectionAbstract
The volume and sophistication of network attacks have grown faster than the signature databases on which conventional intrusion detection systems depend, and behaviour-based anomaly detection has become the principal alternative. This paper reports a controlled comparison of a random forest (RF) classifier and a multilayer perceptron artificial neural network (ANN) for binary anomaly detection on the NSL-KDD benchmark, which removes the duplicate records and the unrealistic class distribution of its KDD Cup 1999 predecessor. Both models are trained under a single preprocessing pipeline consisting of label standardisation, one-hot encoding of the three nominal attributes, a logarithmic transformation of the heavy-tailed volume attributes, min–max scaling to the unit interval, and synthetic minority over-sampling applied to the training partition only. Evaluation on the held-out KDDTest+ partition shows that the two architectures separate along a false-alarm/detection trade-off rather than along overall accuracy. The random forest reaches 76.54% accuracy with 267 false positives and an area under the receiver operating characteristic curve of 0.9609, whereas the neural network reaches 79.85% accuracy and detects 1,221 more attacks, at the cost of 742 false positives and a lower area under the curve of 0.8797. Both models exceed 99% accuracy on the training partition, so the drop of roughly twenty percentage points on the test partition is attributed to attack families that are absent from the training data rather than to a deficiency of either architecture. The serialised models are finally exposed through a packet-capturing web service, so that the comparison is grounded in a deployable prototype and not in an offline benchmark alone.
References
[1] Y. Xin et al., “Machine learning and deep learning methods for cybersecurity,” IEEE Access, vol. 6, pp. 35365–35381, 2018, doi: 10.1109/ACCESS.2018.2836950.
[2] D. Kwon, H. Kim, J. Kim, S. C. Suh, I. Kim, and K. J. Kim, “A survey of deep learning-based network anomaly detection,” Cluster Comput., vol. 22, no. 1, pp. 949–961, 2019, doi: 10.1007/s10586-017-1117-8.
[3] I. Ahmad, M. Basheri, M. J. Iqbal, and A. Rahim, “Performance comparison of support vector machine, random forest, and extreme learning machine for intrusion detection,” IEEE Access, vol. 6, pp. 33789–33795, 2018, doi: 10.1109/ACCESS.2018.2841987.
[4] A. Moldagulova and R. B. Sulaiman, “Using KNN algorithm for classification of textual documents,” in Proc. 8th Int. Conf. Inf. Technol. (ICIT), Amman, Jordan, 2017, pp. 665–671, doi: 10.1109/ICITECH.2017.8079924.
[5] University of California, Irvine, “KDD Cup 1999 task description.” [Online]. Available: https://kdd.ics.uci.edu/databases/kddcup99/task.html (accessed Aug. 22, 2026).
[6] M. Tavallaee, E. Bagheri, W. Lu, and A. A. Ghorbani, “A detailed analysis of the KDD CUP 99 data set,” in Proc. IEEE Symp. Comput. Intell. Secur. Defense Appl. (CISDA), Ottawa, ON, Canada, 2009, pp. 1–6, doi: 10.1109/CISDA.2009.5356528.
[7] Canadian Institute for Cybersecurity, “NSL-KDD dataset,” University of New Brunswick. [Online]. Available: https://www.unb.ca/cic/datasets/nsl.html (accessed Aug. 8, 2026).
[8] L. Dhanabal and S. P. Shantharajah, “A study on NSL-KDD dataset for intrusion detection system based on classification algorithms,” Int. J. Adv. Res. Comput. Commun. Eng., vol. 4, no. 6, pp. 446–452, 2015.
[9] M. C. Belavagi and B. Muniyal, “Performance evaluation of supervised machine learning algorithms for intrusion detection,” Procedia Comput. Sci., vol. 89, pp. 117–123, 2016, doi: 10.1016/j.procs.2016.06.016.
[10] B. Ingre and A. Yadav, “Performance analysis of NSL-KDD dataset using ANN,” in Proc. Int. Conf. Signal Process. Commun. Eng. Syst. (SPACES), Guntur, India, 2015, pp. 92–96, doi: 10.1109/SPACES.2015.7058223.
[11] S. Revathi and A. Malathi, “A detailed analysis on NSL-KDD dataset using various machine learning techniques for intrusion detection,” Int. J. Eng. Res. Technol., vol. 2, no. 12, pp. 1848–1853, 2013.
[12] MIT Lincoln Laboratory, “1998 DARPA intrusion detection evaluation dataset.” [Online]. Available: https://www.ll.mit.edu/r-d/datasets/1998-darpa-intrusion-detection-evaluation-dataset (accessed Aug. 22, 2026).
[13] L. Yu, R. Zhou, R. Chen, and K. K. Lai, “Missing data preprocessing in credit classification: One-hot encoding or imputation?,” Emerg. Markets Finance Trade, vol. 58, no. 2, pp. 472–482, 2022, doi: 10.1080/1540496X.2020.1825935.
[14] A. Singh, J. Amutha, J. Nagar, S. Sharma, and C.-C. Lee, “LT-FS-ID: Log-transformed feature learning and feature-scaling-based machine learning algorithms to predict the k-barriers for intrusion detection using wireless sensor network,” Sensors, vol. 22, no. 3, art. no. 1070, 2022, doi: 10.3390/s22031070.
[15] M. Shantal, Z. Othman, and A. A. Bakar, “A novel approach for data feature weighting using correlation coefficients and min–max normalization,” Symmetry, vol. 15, no. 12, art. no. 2185, 2023, doi: 10.3390/sym15122185.
[16] N. V. Chawla, K. W. Bowyer, L. O. Hall, and W. P. Kegelmeyer, “SMOTE: Synthetic minority over-sampling technique,” J. Artif. Intell. Res., vol. 16, pp. 321–357, 2002, doi: 10.1613/jair.953.
[17] L. Breiman, "Random forests," Mach. Learn., vol. 45, no. 1, pp. 5–32, 2001, doi: 10.1023/A:1010933404324.
[18] D. P. Kingma and J. Ba, "Adam: A method for stochastic optimization," in Proc. 3rd Int. Conf. Learn. Represent. (ICLR), San Diego, CA, USA, 2015. [Online]. Available: https://arxiv.org/abs/1412.6980
Downloads
Published
Issue
Section
License
Copyright (c) 2026 Cennet Büşra Hakay, Sevdanur GENÇ (Author)

This work is licensed under a Creative Commons Attribution-NonCommercial 4.0 International License.