This repository contains an academic project analyzing how different data preprocessing and sampling techniques affect the performance of a Decision Tree classifier. The primary focus is on detecting Network/DDoS attacks using the highly imbalanced CIC-IDS-2018 dataset.
Real-world cybersecurity datasets are often heavily imbalanced, where normal traffic vastly outnumbers attack instances. This project evaluates three sampling approaches to address this issue:
- Random Sampling (Baseline) - Original imbalanced distribution.
- Undersampling (RandomUnderSampler) - Reducing the majority class.
- Oversampling (SMOTE) - Synthetically generating minority class instances.
A detailed Polish report is available in the docs/ folder.
Based on the experiments, SMOTE oversampling proved to be the most effective method:
- Achieved 99.93% overall accuracy.
- Perfectly classified (100% Precision, Recall, and F1-score) the severely underrepresented minority class (
DDOS attack-LOIC-UDP), which originally had only 15 instances in the raw dataset. - Produced the most balanced and representative logical rules for the Decision Tree.
├── data/
│ ├── README.md # Data directory documentation
│ └── download_data.py # Automated Kaggle dataset downloader
├── docs/
│ ├── README.md # Documentation overview
│ └── project_report_PL.pdf # Comprehensive project report (PL)
├── src/
│ ├── README.md # Source code documentation
│ ├── oversampling_smote.py # SMOTE implementation
│ ├── random_sampling.py # Baseline classification
│ └── undersampling.py # Random Undersampling implementation
├── .gitattributes # Git attributes configuration
├── .gitignore # Git ignore file
├── README.md # Main project documentation
└── requirements.txt # Python dependencies
Clone this repository and install the required Python packages:
pip install -r requirements.txtThis project uses an automated script to download the specific ~300MB CSV file (02-21-2018.csv) from the 7GB CSE-CIC-IDS2018 Kaggle dataset.
- Create a Kaggle account.
- Go to your Account Settings -> API -> Create New Token.
- Place the downloaded kaggle.json file in your system's Kaggle folder (e.g., ~/.kaggle/kaggle.json on Linux/Mac or C:\Users<User>.kaggle\kaggle.json on Windows).
Run the automated downloader script from the root directory:
python download_data.pyThe script will automatically download the archive, extract the required CSV file into the data/ folder, and clean up the temporary files.
Once the data is downloaded, you can run any of the models from the root directory.
To test the SMOTE oversampling method:
python src/oversampling_smote.pyTo test the random undersampling method:
python src/undersampling.pyTo test the baseline random sampling:
python src/random_sampling.pyKacper Lis
Student of Data Engineering and Analysis