An interactive web-based visualization of the K-Means clustering algorithm using amCharts. This visualization demonstrates how the K-Means algorithm organizes random data points into distinct clusters through multiple iterations.
K-Means is one of the most popular unsupervised machine learning algorithms used for clustering data. This project provides a step-by-step visual demonstration of how K-Means works:
- Random data points are generated and scattered across the visualization area
- Initial centroids are placed strategically on the canvas
- Points are assigned to their nearest centroid, forming initial clusters
- Centroids are recalculated based on their assigned points
- Multiple iterations of the algorithm are performed to refine clusters
- Final clusters are displayed with distinct colors
- Animated visualization of the K-Means algorithm
- Multiple iterations showing how clusters evolve
- Color-coded points to indicate cluster membership
- Dynamic centroid recalculation and movement
- Smooth transitions between algorithm steps
To run the demo:
- Clone this repository
- Open
index.htmlin your web browser - Watch the K-Means clustering algorithm in action!
The visualization is built using:
- HTML5/CSS3 for page structure and styling
- JavaScript for implementing the K-Means algorithm
- amCharts 5 library for smooth animations and data visualization
index.html: Main HTML file to display the visualizationstyle.css: Styling for the visualizationscript.js: Implementation of the K-Means algorithm and visualization logic
The implementation follows these key steps:
- Initialization: 50 random data points are generated
- Initial Centroid Placement: Starting with 2 centroids, then expanding to 6
- Assignment: Each point is assigned to the nearest centroid
- Update: Centroids are recalculated based on the mean position of all points in their cluster
- Iteration: Steps 3-4 are repeated for
NumOfIterations(currently set to 10)
Potential enhancements for this project:
- Add user controls to adjust parameters (number of points, clusters, iterations)
- Implement different initialization methods (random, k-means++, etc.)
- Add metrics to show clustering quality
- Allow users to draw their own datasets