Spaces:
Sleeping
Sleeping
A newer version of the Streamlit SDK is available:
1.55.0
metadata
title: NSL-KDD Anomaly Detection
emoji: π§
colorFrom: blue
colorTo: green
sdk: streamlit
app_port: 8501
pinned: false
tags:
- anomaly-detection
- machine-learning
- streamlit
- cybersecurity
π§ NSL-KDD Anomaly Detection (Isolation Forest vs One-Class SVM vs Logistic Regression)
This Streamlit web app performs network intrusion detection using the NSL-KDD dataset,
comparing both unsupervised and supervised machine learning algorithms.
π Live Demo
π Try it on Hugging Face Spaces:
(Replace this link with your Space URL after deployment)
π§ Overview
The app demonstrates anomaly detection for cybersecurity by comparing three models:
| Model | Type | Description |
|---|---|---|
| Isolation Forest | Unsupervised | Detects anomalies by isolating data points |
| One-Class SVM | Unsupervised | Learns a decision boundary around normal data |
| Logistic Regression | Supervised | Classifies known attacks using labeled data |
The dataset comes from the NSL-KDD benchmark β an improved version of the KDD Cup '99 dataset.
βοΈ Workflow
- Load the NSL-KDD dataset from an online source
- One-hot encode categorical columns (
protocol_type,service,flag) - Scale all numeric features with
StandardScaler - Train and compare all three models
- Display metrics and confusion matrices in Streamlit
π Example Outputs
- Model Performance Table β Accuracy, Precision, Recall, F1-score
- Confusion Matrices β For all three models
- Visual Insights β Easy comparison between supervised and unsupervised models
π§Ύ Dataset
Source: University of New Brunswick β NSL-KDD Dataset
It contains 41 features describing network traffic and a label (normal or attack).
π§° Tech Stack
- Python 3.9+
- Streamlit β Web framework
- Scikit-learn β ML algorithms & preprocessing
- Matplotlib / Seaborn β Visualization
- Pandas / NumPy β Data handling
ποΈ Local Setup (Optional)
# Clone the repo
git clone https://huggingface.co/spaces/your-username/nsl-kdd-anomaly-detection
cd nsl-kdd-anomaly-detection
# Install dependencies
pip install -r requirements.txt
# Run Streamlit app
streamlit run app.py