MinhTien30122003/SVM_vs_CNN
0
Spiral SVM vs ANN Benchmark Demo
A small web benchmark comparing SVM (RBF, scikit-learn) and ANN (PyTorch) on spiral classification variants. The current app is intentionally visual-first: users train and compare boundaries for 2-spiral and 3-spiral notebook-style benchmarks.
Live demo (Hugging Face Spaces): SVM_vs_CNN
Features
- Visual side-by-side boundary comparison: SVM vs ANN.
- Benchmark variants restricted to 2 spirals and 3 spirals.
- Notebook-aligned setup for key comparisons (including 3-spiral SVM behavior).
- Clean FastAPI backend with a single benchmark API endpoint.
- Lightweight UI with per-variant discussion notes shown after training completes.
Architecture (summary)
Project layout
Spiral_SVM_ANN_Demo/
├── src/
│ ├── app.py # FastAPI routes + /demo UI HTML
│ ├── inference.py # Spiral generation, train/compare, boundary rendering
│ └── modeling.py # ANN module definitions + CSV loader
├── scripts/
│ └── train_models.py # Export base SVM/ANN artifacts for app startup
├── requirements.txt
├── Dockerfile # Docker deploy (HF Spaces: port 7860)
├── DEPLOY.md # Deployment notes
├── models/
│ ├── svm_rbf.joblib
│ └── ann_state_dict.pt
├── data/
│ └── spiralsdataset.csv
└── static/css/
├── theme.css
└── components.cssLocal setup
Requirements: Python 3.10+ (recommended), pip.
cd Spiral_SVM_ANN_Demo
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
pip install -r requirements.txtPrepare model artifacts
python scripts/train_models.pyRun the server
uvicorn src.app:app --reload --host 0.0.0.0 --port 7860- Demo: http://127.0.0.1:7860/demo
- API docs: http://127.0.0.1:7860/docs
Environment variables (optional)
API overview
See /docs for request/response schemas.
Deployment
- Hugging Face Spaces (Docker): use this repo with
Dockerfile(port7860). - Optional workflow notes in
DEPLOY.md.
Benchmark notes
- 2-spiral: SVM often produces a smoother visual boundary than ANN.
- 3-spiral: with notebook-aligned setup, both can fit strongly in benchmark mode.
- This app is configured as a visual benchmark (not a point-by-point prediction tool).
License
Educational / portfolio demo; source and weights are governed by your own repository terms.
