r/PythonLearning • • May 17 '26

Real-time Network Traffic Classifier using Random Forest, FastAPI, and Streamlit (96.8% Accuracy)

I recently built an AI-powered Network Traffic Classifier that detects network intrusions in real-time, and I'm sharing it for feedback from this community.

🔒 What it does:

The system analyzes network traffic patterns and automatically classifies them as Normal ✅ or Malicious ⚠️ (DoS, Probe, R2L, U2R attacks) using a Random Forest model trained on the NSL-KDD dataset.

Key metrics:

- 96.8% overall accuracy (Precision: 96.81%, Recall: 96.8%)

- <1ms inference time per prediction

- 200 decision trees, 12 network features analyzed

🛠️ Tech Stack:

- ML: Random Forest (scikit-learn)

- Backend: FastAPI with OpenAPI docs

- Frontend: Streamlit (6-page dashboard)

- Deployment: Docker & Docker Compose

- Dataset: NSL-KDD (5,000 simulated samples)

📂 GitHub Repo:

https://github.com/GulrezQayyum/network-traffic-classifier-model

🚀 Quick Start (2 mins):

```bash

git clone [https://github.com/GulrezQayyum/network-traffic-classifier-model.git](https://github.com/GulrezQayyum/network-traffic-classifier-model.git)

cd network-traffic-classifier-model && docker-compose up -d

# Dashboard: localhost:8501 | API Docs: localhost:8000/docs

What I'd love from you:

  • Feedback on the model architecture or feature selection

  • Suggestions for improving real-world accuracy (currently 96.8% on benchmark data)

  • Ideas for additional threat detection features

  • Any edge cases I should test for

I know I'm new to Reddit and can't upload videos yet, but I'm happy to answer questions or share more details in comments. Thanks in advance for your time!

0 Upvotes

Duplicates