Skip to content

Repository files navigation

Network Traffic Prediction using Machine Learning

🚀 IMPORTANT

This repository supports two different workflows:

Method 1 — Wireshark Traffic Prediction

Use this if you have:

  • .pcapng files
  • Wireshark packet captures
  • Wireshark text exports

Method 2 — Kaggle Dataset Training

Use this if you downloaded datasets such as:

  • CIC-IDS2017
  • UNSW-NB15
  • KDD Cup 1999
  • Network Traffic Flows

➡️ If you are using a Kaggle dataset, skip directly to Method 2.


🤗 Hosted Model

Hugging Face

The trained model from this project is published on Hugging Face — you can browse or download it directly instead of retraining from scratch.


Features

Wireshark Workflow

  • Analyze real network captures
  • Parse .pcapng and Wireshark exports
  • Generate traffic statistics
  • Predict future traffic metrics
  • Generate reports and visualizations

Kaggle Workflow

  • Train ML models from network datasets
  • Automatic dataset column mapping
  • Forecast future traffic
  • Save reusable models
  • Generate feature importance charts

Repository Structure

Network-Traffic-Prediction-using-Machine-Learning/
│
├── run.py
├── traffic_predictor.py
├── visualize.py
├── generate_sample_data.py
│
├── kaggle_train.py
├── kaggle_predict.py
│
├── requirements.txt
└── README.md

METHOD 1 — Wireshark Traffic Prediction

Use this workflow if you have real packet capture files.

Supported Formats

Format Description
.pcapng Wireshark capture
.txt Wireshark plain text export

Installation

pip install -r requirements.txt

Run Using PCAPNG

python run.py capture.pcapng

Run Using Wireshark Text Export

python run.py capture.txt

Demo Mode

python run.py

Available Options

--window N

Aggregation window in seconds.

--model-dir

Directory for trained models.

--output-dir

Directory for reports and charts.

--no-plots

Disable graph generation.


Output Files

output/
├── prediction_output.txt
├── prediction_report.json
└── plots/
    ├── dashboard.png
    ├── protocol_distribution.png
    └── traffic_timeseries.png

Wireshark Export Instructions

  1. Open capture in Wireshark
  2. File → Export Packet Dissections
  3. Select "As Plain Text"
  4. Enable "Packet Bytes"
  5. Save as .txt

Wireshark Prediction Outputs

Throughput / Bandwidth

Example:

At 3:00 PM tomorrow,
the incoming traffic will be 1.2 Gbps.

Packet Count

Example:

We expect 15,000 packets per second
during the next prediction window.

Link Utilization

Example:

The backbone link will be at 78%
capacity between T1 and T2.

METHOD 2 — Kaggle Dataset Training

⚠️ If you downloaded a dataset from Kaggle, start here.


Recommended Datasets

CIC-IDS2017 (Recommended)

https://www.kaggle.com/datasets/cicdataset/cicids2017

UNSW-NB15

https://www.kaggle.com/datasets/mrwellsdavid/unsw-nb15

Network Traffic Flows

https://www.kaggle.com/datasets/jsrojas/ip-network-traffic-flows-labeled-with-87-apps

KDD Cup 1999

https://www.kaggle.com/datasets/galaxyh/kdd-cup-1999-data


Download Dataset

Option A — Manual Download

  1. Open dataset page
  2. Click Download
  3. Extract ZIP
  4. Place CSV file beside kaggle_train.py

Option B — Kaggle API

Install Kaggle:

pip install kaggle

Create API token:

https://www.kaggle.com/settings

Download dataset:

kaggle datasets download -d cicdataset/cicids2017 --unzip

Train Models

Basic training:

python kaggle_train.py --file dataset.csv

Example:

python kaggle_train.py --file Friday-WorkingHours.csv

Custom model directory:

python kaggle_train.py --file dataset.csv --model-dir kaggle_models

Limit rows:

python kaggle_train.py --file dataset.csv --rows 500000

Models Trained

Three independent Gradient Boosting models are created:

Model Prediction
Model 1 Throughput/Bandwidth (Mbps)
Model 2 Packet Count (pkt/s)
Model 3 Link Utilization (%)

Training Output

kaggle_models/
├── kaggle_throughput_mbps_model.pkl
├── kaggle_throughput_mbps_scaler.pkl
├── kaggle_packet_count_model.pkl
├── kaggle_packet_count_scaler.pkl
├── kaggle_link_util_pct_model.pkl
├── kaggle_link_util_pct_scaler.pkl
├── kaggle_training_metrics.json
└── feature_importance_plots

Predict Future Traffic

Interactive mode:

python kaggle_predict.py --model-dir kaggle_models

Predict using new CSV:

python kaggle_predict.py \
    --model-dir kaggle_models \
    --file new_data.csv

Custom forecast:

python kaggle_predict.py \
    --model-dir kaggle_models \
    --steps 20 \
    --window 60

Disable graph:

python kaggle_predict.py \
    --model-dir kaggle_models \
    --no-plot

Kaggle Prediction Outputs

Throughput / Bandwidth

At 3:00 PM tomorrow,
the incoming traffic will be X Mbps/Gbps.

Packet Count

We expect X,XXX packets per second
during the next prediction window.

Link Utilization

The backbone link will operate at X% capacity.

Machine Learning Pipeline

Raw Network Data
       │
       ▼
Feature Engineering
       │
       ▼
Traffic Metrics
       │
       ▼
Gradient Boosting Regressor
       │
       ├── Throughput Model
       ├── Packet Count Model
       └── Link Utilization Model
       │
       ▼
Future Traffic Forecast
       │
       ▼
Reports + Visualizations

Technologies Used

  • Python
  • Pandas
  • NumPy
  • Scikit-Learn
  • Matplotlib
  • Joblib

Quick Start

For Wireshark Users

pip install -r requirements.txt

python run.py capture.pcapng

For Kaggle Users

pip install -r requirements.txt

python kaggle_train.py --file dataset.csv

python kaggle_predict.py --model-dir kaggle_models

About

Machine learning model for network traffic prediction to improve bandwidth planning and performance analysis.

Resources

Stars

2 stars

Watchers

0 watching

Forks

Contributors

Languages