An interactive and dynamic web-based visualization of the K-Means clustering algorithm, combining mathematical precision with captivating animations.
This project visually demonstrates the K-Means clustering algorithm through smooth animations and progressive iterations. By splitting centroids and dynamically updating clusters, it showcases the power of machine learning algorithms in an intuitive and engaging way.
Key Highlights:
- Dynamic point generation and clustering.
- Progressive centroid splitting with adaptive deviations.
- Smooth animations and color transitions for clear understanding.
- amCharts 5: For visualizing and animating the clustering process.
- Bootstrap: Ensures a responsive and user-friendly design.
- JavaScript/TypeScript: Powers the core clustering logic and animations.
index.html
: The Bootstrap-based UI layout.style.css
: Contains custom styles for a modern look.script.js
: Implements clustering and animation logic.math.txt
: Documents the mathematical foundations of the clustering algorithm.
- Smooth animations of points and centroids.
- Color-coded clusters for clarity.
- Progressive splitting of centroids.
- Adaptive deviation-based clustering.
- Dynamic point-to-centroid assignment.
- Scalable cluster count (based on configurable iterations).
- Modern, responsive design.
- Informative cards explaining the algorithm's progress.
- Interactive and intuitive interface.
-
Initial Setup:
- Generate points and place them around a single centroid.
- Configure the maximum number of iterations (
MAX_ITERATIONS
).
-
Clustering Process:
- At each iteration:
- Centroids split into new positions with reduced deviations.
- Points are assigned to the nearest centroid using Euclidean distance.
- Clusters are color-coded based on membership.
- At each iteration:
-
Animation Sequences:
- Points scatter from a central position.
- Centroids split, move, and recalibrate dynamically.
- Clusters smoothly transition to updated colors.
- Euclidean Distance: Calculates point-to-centroid proximity.
- Vector Normalization: Ensures smooth and adaptive positioning.
- Adaptive Deviations: Refines clustering precision with each iteration.
let their_positions_after_movement = [];
let circles_objects = [];
let current_centroids = [initial_centroid_location];
function performIteration() {
// Splits centroids and recalculates cluster memberships
// Updates point positions and colors
}
- Initial Scatter:
200ms
delays between points. - Cluster Updates:
2000ms
intervals for animations. - Iteration Spacing:
4000ms
between centroid splits.
🎬 Watch the Project in Action: Demo Video
(Upload a video showing the clustering process, from the initial scatter to the final iteration.)
-
Progressive Splitting:
- Centroids split dynamically, forming a tree-like structure.
- Adaptive deviations for increased precision.
-
Dynamic Animations:
- Smooth transitions for both points and centroids.
- Staggered animations create a visually appealing flow.
-
Mathematical Precision:
- Optimized calculations for clustering accuracy.
- Intuitive visuals to explain algorithmic complexity.
- Clone the repository:
git clone /~https://github.com/DEVOLOPER-1/K-Means-Visualizer
- Open
index.html
in your browser to view the visualization. - Modify
MAX_ITERATIONS
inscript.js
to adjust clustering depth.
- Adding support for custom datasets.
- Implement additional clustering algorithms (e.g., DBSCAN, Hierarchical).
- Provide an interactive slider for real-time iteration control.
For questions or feedback, feel free to reach out:
- Linkedin: Youssef Mohammad
- GitHub: DEVOLOPER-1