A visualization of the k-means algorithm written in V.
This project has been written in a few hours in order to learn gg
, the graphical library of V. It is inspired by a livestream of Tsoding where he did the same project in C, using raylib
.
Before you try running this program, make sure you have installed V, following the instructions from the V documentation. Then, after cloning this repo, run the following command:
v run .
This should start the visualization.
Once the window is open:
- press
space
to perform a single iteration of the k-means algorithm (holding space works) - press
r
to reset the visualization (generate a new dataset and start k-means from step 0). - press
q
to close the window and quit the program.
By default, the dataset consists of 500 points, split in 3 gaussians randomly placed and spread in the window, generated each time you start the program. You can change the number of clusters and the number of points by respectively setting k
and n
in the beginning of file ./src/main.v.
Here are some links you might want to follow if you liked this repo:
- Tsoding stream that inspired this project: Data mining in C
- K-means on Wikipedia
- V language