Interactive machine learning visualization application that demonstrates how the K-Means Clustering algorithm works step by step.
The project is designed as an educational tool for learning machine learning fundamentals, clustering algorithms, data visualization, and modern software engineering practices.
- Generate random 2D datasets
- Configure the number of points
- Return datasets through FastAPI API
- Prepare datasets for clustering experiments
- Custom K-Means implementation using NumPy
- Configurable number of clusters (k)
- Configurable maximum number of iterations
- Random centroid initialization
- Point-to-centroid assignment
- Centroid recalculation
- Inertia (loss) calculation
- Iteration history tracking
- Final centroid calculation
- Backend Docker container
- Frontend Docker container
- Docker Compose orchestration
- One-command local environment startup
- Containerized FastAPI application
- Containerized React application
- Backend Deployment
- Frontend Deployment
- Backend Service
- Frontend Service
- Kubernetes Ingress
- Internal service discovery
- Container orchestration with Kubernetes
- Local Kubernetes deployment support
- Backend Horizontal Pod Autoscaler (HPA)
- CPU-based autoscaling configuration
- Kubernetes ConfigMap configuration management
- Resource requests and limits
- Liveness probes
- Readiness probes
- Health monitoring through Kubernetes
- One-command Kubernetes deployment
- Automatic Docker image builds
- Automatic Kubernetes resource deployment
- Automated deployment rollout verification
- Automated cluster cleanup
- Automated port-forwarding setup
- Enhanced centroid movement visualization
- Inertia charts
- Cluster assignment visualization improvements
- Responsive UI
- Dark mode
- Linear Regression Visualizer
- Automated backend quality checks
- Automated frontend linting
- Automated frontend production build verification
- Automated Docker image builds
- Automated Kubernetes manifest validation
- GitHub Actions CI workflow
- Python 3.13
- FastAPI
- NumPy
- React
- Vite
- JavaScript
- Axios
- SVG Visualization
- Docker
- Docker Compose
- Kubernetes
- Ingress
- GitHub Actions
KMeansVisualizer/
.github/
βββ workflows/
β βββ ci.yml
βββ backend/
β βββ schemas/
β β βββ __init__.py
β β βββ dataset.py
β β βββ kmeans.py
β β
β βββ services/
β β βββ __init__.py
β β βββ dataset_service.py
β β βββ kmeans_service.py
β β
β βββ Dockerfile
β βββ .dockerignore
β βββ main.py
β βββ requirements.txt
β βββ pyproject.toml
β
βββ frontend/
β βββ public/
β β
β βββ src/
β β βββ assets/
β β βββ components/
β β β βββ ClusteringMetrics.jsx
β β β βββ DatasetGenerator.jsx
β β β βββ IterationControls.jsx
β β β βββ KMeansControls.jsx
β β β βββ ScatterPlot.jsx
β β β
β β βββ services/
β β β βββ api.js
β β β
β β βββ App.jsx
β β βββ App.css
β β βββ index.css
β β βββ main.jsx
β β
β βββ Dockerfile
β βββ .dockerignore
β βββ package.json
β βββ package-lock.json
β βββ vite.config.js
β βββ eslint.config.js
β
βββ k8s/
β βββ backend-deployment.yaml
β βββ backend-service.yaml
β βββ frontend-deployment.yaml
β βββ frontend-service.yaml
β βββ backend-hpa.yaml
β βββ configmap.yaml
β βββ ingress.yaml
β
βββ scripts/
β βββ deploy-k8s.ps1
β βββ destroy-k8s.ps1
β βββ port-forward.ps1
β
βββ docker-compose.yml
βββ README.md
βββ .gitignore
git clone <repository-url>
cd KMeansVisualizercd backend
py -m venv venv.\venv\Scripts\Activate.ps1pip install -r requirements.txtpython -m uvicorn main:app --reloadBackend will be available at:
http://localhost:8000
Swagger UI:
http://localhost:8000/docs
cd frontend
npm installnpm run devFrontend will be available at:
http://localhost:5173npm run builddocker compose up --buildServices will be available at:
Frontend: http://localhost:5173
Backend: http://localhost:8000
Swagger: http://localhost:8000/docs
docker compose downdocker build -t kmeans-backend:latest ./backend
docker build -t kmeans-frontend:latest ./frontendkubectl apply -f k8s/kubectl get pods
kubectl get services
kubectl get ingresskubectl get hpa
kubectl describe hpa kmeans-backend-hpakubectl get configmaps
kubectl describe configmap kmeans-configkubectl describe pod <pod-name>kubectl port-forward service/kmeans-backend-service 8000:8000Backend will be available at:
http://localhost:8000
kubectl port-forward service/kmeans-frontend-service 5173:5173Frontend will be available at:
http://localhost:5173
kubectl delete -f k8s/.\scripts\deploy-k8s.ps1This script:
- Removes previous Kubernetes resources
- Builds backend Docker image
- Builds frontend Docker image
- Deploys all Kubernetes manifests
- Waits for deployment rollout
- Displays cluster status
.\scripts\destroy-k8s.ps1This script:
- Removes all Kubernetes resources
- Displays remaining cluster resources
.\scripts\port-forward.ps1This script:
- Opens backend port forwarding
- Opens frontend port forwarding
- Provides local access to the application
GET /healthResponse:
{
"status": "ok"
}POST /datasets/generateRequest:
{
"points": 100
}Response:
{
"points": [
[12.5, 45.1],
[22.8, 11.3]
]
}POST /kmeans/stepsRequest:
{
"points": [
[1, 2],
[2, 1],
[8, 9],
[9, 8]
],
"k": 2,
"max_iterations": 10
}Response:
{
"iterations": [...],
"final_centroids": [...]
}Swagger UI:
http://localhost:8000/docs
- Dataset generation UI
- K-Means execution UI
- Scatter plot visualization
- Cluster color visualization
- Centroid visualization
- Iteration slider
- Previous / Next controls
- Play / Pause animation
- Reset animation
- Clustering metrics dashboard
- Root API endpoint
- Health check endpoint
- Dataset generation API
- K-Means clustering API
- Iteration tracking
- Inertia calculation
- Swagger documentation
- Dockerized backend
- Dockerized frontend
- Docker Compose environment
- Kubernetes deployments
- Kubernetes services
- Kubernetes ingress
- Horizontal Pod Autoscaler (HPA)
- ConfigMap-based configuration
- Health monitoring probes
- Resource limits and requests
- Automated Kubernetes deployment scripts
- Automated Kubernetes cleanup scripts
- Automated port-forwarding scripts
The project includes an automated CI workflow executed on every push and pull request.
- Backend Ruff linting
- Backend Black formatting verification
- Frontend ESLint verification
- Frontend production build verification
- Backend Docker image build
- Frontend Docker image build
- Kubernetes manifest validation
.github/workflows/ci.yml
cd backend
py -m black .cd backend
py -m ruff check .cd backend
py -m ruff check . --fixcd frontend
npm run lintdocker compose configdocker build -t kmeans-backend ./backenddocker build -t kmeans-frontend ./frontendkubectl apply --dry-run=client -f k8s/kubectl get pods
kubectl get services
kubectl get ingresskubectl get hpakubectl describe hpa kmeans-backend-hpakubectl get configmapskubectl describe pod <pod-name>Black- Python formatterRuff- Python linterReact- Frontend UIVite- Frontend toolingAxios- API communicationFastAPI- Backend APISwagger UI- API documentationDocker- ContainerizationDocker Compose- Local orchestrationKubernetes- Container orchestrationIngress- Traffic routingHorizontal Pod Autoscaler(HPA) - Automatic scalingConfigMap- Configuration managementLiveness Probe- Container health checksReadiness Probe- Traffic readiness checksPowerShell Scripts- Kubernetes automationGitHub Actions- Continuous Integration
This project demonstrates:
- Machine Learning Fundamentals
- K-Means Clustering Algorithm
- Numerical Computing with NumPy
- FastAPI Backend Development
- API Design and Validation
- React State Management
- API Integration with Axios
- Interactive Algorithm Visualization
- Frontend-Backend Communication
- Data Visualization
- Docker Containerization
- Docker Compose Orchestration
- Kubernetes Deployments
- Kubernetes Services
- Kubernetes Ingress
- Kubernetes Horizontal Pod Autoscaling
- Kubernetes ConfigMaps
- Kubernetes Health Checks
- Resource Management in Kubernetes
- Application Monitoring Concepts
- Infrastructure Automation
- Kubernetes Operational Workflows
- Deployment Automation
- CI/CD Automation

