This research explores an improved Network Intrusion Detection System (NIDS) on the NSL-KDD dataset using machine learning, deep learning and ensemble learning methods. Our approach involves essential steps such as data preparation, feature engineering with Random Forest, feature reduction, model building, hyperparameter tuning with GridSearchCV, and evaluation. We perform binary and multiclass classification tasks with Naïve Bayes, Logistic Regression, Random Forest, LightGBM, CNN, and LSTM approaches. The findings show ensemble techniques enhance classification accuracy. Random Forest and LightGBM models in binary classification, and CNN and LSTM models in multiclass classification achieved up to 99% and 97.99% and 97.80% accuracy, respectively. Additionally, the proposed stacked ensemble model, with XGBoost as the meta-learner, achieved a final test accuracy of 99.03%, and improved precision, recall, F1-score and ROC-AUC compared to the individual models. Tuning the hyperparameters also improved model stability and accuracy. This research is novel in combining feature selection, hyperparameter-tuned deep learning models and a stacking ensemble to enhance accuracy and stability in intrusion detection. The research also emphasizes the need for interpretability, real-time considerations and transfer learning in future NIDS research.
Copyrights © 2026