This example demonstrates combining the geometry module with machine learning for 3D spatial clustering and visualization.
- Using geometry module for 3D points
- Applying ML clustering to geometric data
- Visualizing 3D clusters
- Combining multiple VSL modules
- V compiler installed (download here)
- VSL library installed (installation guide)
- No additional system dependencies required
# Navigate to this directory
cd examples/geometry_ml_clustering
# Run the example
v run main.vThe example generates:
- Console output: Data generation, training progress, and accuracy
- 3D Plot: Visualization of clusters with centroids marked
import vsl.gm
import rand
rand.seed([u32(12345), u32(67890)])
mut points := []gm.Point{}
// Create 3D points using geometry module
x, y, z := 1.0, 2.0, 3.0
points << gm.Point.new(x, y, z)We use the geometry module to create 3D points representing two clusters.
import vsl.gm
mut feature_matrix := [][]f64{}
points := []gm.Point{} // Assume populated
// Convert to feature matrix (2D projection for Kmeans)
for p in points {
feature_matrix << [p.x, p.y]
}Geometry points are converted to feature vectors for ML algorithms.
We apply K-means clustering and visualize results in 3D space.
- Spatial Analysis: Cluster geographic or spatial data
- Point Cloud Processing: Analyze 3D point clouds
- Robotics: Cluster sensor readings in 3D space
- Computer Vision: Segment 3D objects
Try modifying the example to:
- More clusters: Add a third or fourth cluster
- Different geometries: Use different point distributions
- Distance metrics: Use geometry module's distance functions
- Real data: Import actual 3D point cloud data
- Visualization: Add cluster boundaries or surfaces
gm_basic_geometry- Basic geometry operationsml_kmeans- K-means clusteringplot_scatter3d_1- 3D plotting
Low accuracy: Try different initial centroids
Plot doesn't open: Ensure web browser is installed
Module errors: Verify VSL installation
Explore more geometry and ML examples in the examples directory.