Skip to content

k-means clustering with support for silhouette scoring and k-means++.

Notifications You must be signed in to change notification settings

dkgv/go-k-means

Repository files navigation

go-k-means

Coverage Status

A simple Go k-means clustering library with support for k-means++ centroid initialization and k value evaluation via silhouette scoring.

Usage

package main

import k_means "github.com/dkgv/go-k-means"

func main() {
    data := []k_means.Datum{
        // ...
    }
	
    randomSeed := 0
    km := k_means.New(
        k_means.WithMinIterations(1)
        k_means.WithMaxIterations(100),
        k_means.WithKMeansPlusPlusCentroidStrategy(randomSeed),
        // k_means.WithRandomCentroidStrategy(randomSeed),
    )
	
    // Find k value and return clustering
    maxK := 5
    clusters := km.Fit(data, maxK)

    // Score clustering
    score := k_means.Score(clusters)	
	
    // Cluster data using a specific k value
    k := 3
    clusters := km.Cluster(data, k)
}

About

k-means clustering with support for silhouette scoring and k-means++.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages