Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mash/gokmeans
K-means algorithm implemented in Go (golang)
https://github.com/mash/gokmeans
Last synced: about 2 months ago
JSON representation
K-means algorithm implemented in Go (golang)
- Host: GitHub
- URL: https://github.com/mash/gokmeans
- Owner: mash
- License: apache-2.0
- Created: 2017-02-15T12:50:49.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-06-08T20:02:18.000Z (over 5 years ago)
- Last Synced: 2024-08-01T04:02:17.127Z (4 months ago)
- Language: Go
- Size: 10.7 KB
- Stars: 20
- Watchers: 3
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-golang-ai - gokmeans - means algorithm implemented in Go (golang). (Cluster)
README
gokmeans
======A Go (golang) package that implements the K-means clustering algorithm.
Goroutines are used throughout to do some calulations concurrently.
#### Get package
`go get github.com/mdesenfants/gokmeans`
#### Example
```
package mainimport (
"fmt"
"github.com/mdesenfants/gokmeans"
)var observations []gokmeans.Node = []gokmeans.Node {
gokmeans.Node{20.0, 20.0, 20.0, 20.0},
gokmeans.Node{21.0, 21.0, 21.0, 21.0},
gokmeans.Node{100.5, 100.5, 100.5, 100.5},
gokmeans.Node{50.1, 50.1, 50.1, 50.1},
gokmeans.Node{64.2, 64.2, 64.2, 64.2},
}func main() {
// Get a list of centroids and output the values
if success, centroids := gokmeans.Train(observations, 2, 50); success {
// Show the centroids
fmt.Println("The centroids are")
for _, centroid := range centroids {
fmt.Println(centroid)
}// Output the clusters
fmt.Println("...")
for _, observation := range observations {
index := gokmeans.Nearest(observation, centroids)
fmt.Println(observation, "belongs in cluster", index+1, ".")
}
}
}
```