It was forked from the following repositories, which don't seem to be maintained anymore:
- https://github.com/okhowang/clusters
- https://github.com/mpraski/clusters
This package also provides utilities for importing data and estimating the optimal number of clusters.
## About
This library was built out of necessity for a collection of performant cluster analysis utilities for Golang. Go, thanks to its numerous advantages (single binary distrubution, relative performance, growing community) seems to become an attractive alternative to languages commonly used in statistical computations and machine learning, yet it still lacks crucial tools and libraries. I use the [*floats* package](https://github.com/gonum/gonum/tree/master/floats) from the robust Gonum library to perform optimized vector calculations in tight loops.
## Installation
If you have Go 1.7+
```bash
go get github.com/photoprism/photoprism/pkg/clusters
```
## Usage
The currently supported hard clustering algorithms are represented by the *HardClusterer* interface, which defines several common operations. To show an example we create, train and use a KMeans++ clusterer:
```go
var data [][]float64
var observation []float64
// Create a new KMeans++ clusterer with 1000 iterations,
// 8 clusters and a distance measurement function of type func([]float64, []float64) float64).
fmt.Printf("Clustered data set into %d\n", c.Sizes())
fmt.Printf("Assigned observation %v to cluster %d\n", observation, c.Predict(observation))
for index, number := range c.Guesses() {
fmt.Printf("Assigned data point %v to cluster %d\n", data[index], number)
}
```
Algorithms currenly supported are KMeans++, DBSCAN and OPTICS.
Algorithms which support online learning can be trained this way using Online() function, which relies on channel communication to coordinate the process:
The Estimator interface defines an operation of guessing an optimal number of clusters in a dataset. As of now the KMeansEstimator is implemented using gap statistic and k-means++ as the clustering algorithm (see https://dl.photoprism.app/pdf/20020106-Estimating_the_Number_of_Clusters.pdf):