CoolFace
Apppublic

mo-01/NIDS-Data-Centric-AI

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes
App README

AI-Driven Network Intrusion Detection System (NIDS)

Course: Quality Assurance

Topic: Machine Learning for Cybersecurity

Author: Mahmoud Abdel Nasser


πŸ“„ Executive Summary

This project delivers a comprehensive Network Intrusion Detection System (NIDS) built on the CICIDS2017 dataset (1 Million records). By applying rigorous Quality Assurance (QA) protocols to data cleaning and feature engineering, I developed a Random Forest Classifier that accurately classifies network traffic into multiple attack types (not just binary classification). The system provides both a Jupyter Notebook for in-depth analysis and an interactive Streamlit Web Application for real-time detection and visualization.


πŸ“Š Dataset Specifications

  • β€”Source: CICIDS2017 (Canadian Institute for Cybersecurity).
  • β€”Initial Volume: ~1,000,000 records from the raw flows.
  • β€”Final Cleaned Dataset: 919,899 records (after removing duplicates and corrupted entries).
  • β€”Target Classes (Multi-Class Classification):
  • β€”Benign: Normal web activity
  • β€”Botnet: Bot-controlled malicious traffic
  • β€”DoS Attacks: Denial of Service (Hulk, GoldenEye, Slowloris, Slowhttptest)
  • β€”DDoS: Distributed Denial of Service
  • β€”PortScan: Network reconnaissance attacks
  • β€”Web Attacks: XSS, Brute Force, and SQL Injection

βœ… Project Phases (Updated)

  1. 1.βœ… Data Collection & Sampling: Stratified sampling from CICIDS2017 dataset (~300K records).
  2. 2.βœ… Data Cleaning (QA): Handling infinite values (inf), nulls, and removing duplicates.
  3. 3.βœ… Exploratory Data Analysis (EDA): Benign vs. Malicious feature comparison (Boxplots), Port 80 targets, and TCP flag patterns.
  4. 4.βœ… Feature Engineering: Multi-class label encoding, standardization via StandardScaler, and explicit removal of redundant features (Avg_Bwd_Segment_Size, etc.).
  5. 5.βœ… Statistical Analysis: Top 20 Feature Importance ranking and correlation analysis.
  6. 6.βœ… Multi-Class Modeling & Validation: Training, testing, and 5-Fold Cross-Validation for attack type prediction.
  7. 7.βœ… Web Application: Interactive Streamlit app for real-time detection and analysis.

βš™οΈ Methodology & Quality Assurance

Data Preprocessing

To ensure the highest data integrity, I implemented a robust pipeline:

  • β€”Infinity Handling: Replaced inf values caused by division-by-zero errors in flow calculations with maximum valid integers.
  • β€”Feature Selection: Dropped highly correlated features (e.g., Avg_Bwd_Segment_Size) to prevent multicollinearity and optimize inference speed.
  • β€”Scaling: Applied Standardization to ensure all network metrics (Durations vs. Packet counts) share the same statistical weight.

Modeling: Random Forest Classifier

The choice of Random Forest was driven by its ensemble nature, providing robustness against overfittingβ€”a critical factor in security QA.


πŸ† Key Results

The model was evaluated on an unseen test set using multi-class classification:

MetricScoreDetails
Overall AccuracyHigh (>95%)Excellent performance across all attack types
Per-Class Precision>95% per classLow false positives for each attack type
Per-Class Recall>90% per classStrong detection of specific attacks
Confusion MatrixClear SeparationDistinct boundaries between attack types
5-Fold Cross-ValidationStable & RobustConsistent performance across data splits

Multi-Class Classification Advantages

  • β€”Identifies specific attack types instead of just "malicious/benign"
  • β€”Enables targeted incident response based on attack category
  • β€”Provides attack severity scoring for prioritization
  • β€”Better support for zero-day attack detection through pattern analysis

πŸ’» How to Use the System

Option 1: Jupyter Notebook (In-Depth Analysis)

bash
jupyter notebook Project.ipynb
  • β€”Full data cleaning pipeline
  • β€”Exploratory data analysis with visualizations
  • β€”Step-by-step model training
  • β€”Detailed performance metrics

Option 2: Streamlit Web Application (Real-Time Detection)

bash
streamlit run streamlit_app.py
  • β€”Upload uncleaned CSV data
  • β€”Automatic data cleaning & preprocessing
  • β€”Interactive exploratory analysis
  • β€”Real-time attack type prediction
  • β€”Download results and trained model
  • β€”Supports files up to 800 MB

πŸ› οΈ Technologies

  • β€”Environment: Jupyter Notebook (Anaconda).
  • β€”Core Libraries: Python 3.13.9, Pandas (Data Manipulation), Scikit-learn (ML Pipeline), Seaborn/Matplotlib (Visualization).
  • β€”Serialization: Joblib (for model persistence).