Updated documentation

This commit is contained in:
Christian Muehlhaeuser
2018-05-27 15:54:41 +02:00
parent 6c6534bdb2
commit 1b576b719c
2 changed files with 15 additions and 3 deletions

View File

@@ -52,14 +52,25 @@ is therefore often considered to be of "linear" complexity in practice,
although it is in the worst case superpolynomial when performed until although it is in the worst case superpolynomial when performed until
convergence. convergence.
## Options
You can greatly reduce the running time by adjusting the required delta You can greatly reduce the running time by adjusting the required delta
threshold. The following code executes the algorithm until less than 5% of the threshold. With the following options the algorithm finishes when less than 5%
data points shifted their cluster assignment in the last iteration: of the data points shifted their cluster assignment in the last iteration:
```go ```go
km, _ := kmeans.NewWithOptions(0.05, false) km, err := kmeans.NewWithOptions(0.05, false)
``` ```
If you are working with two-dimensional data sets, kmeans can generate
beautiful graphs (like the one above) for each iteration of the algorithm:
```go
km, err := kmeans.NewWithOptions(0.01, true)
```
Careful: this will generate PNGs in your current working directory.
## Development ## Development
[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/muesli/kmeans) [![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://godoc.org/github.com/muesli/kmeans)

View File

@@ -26,6 +26,7 @@ func (c Clusters) recenter() {
} }
} }
// reset clears all point assignments
func (c Clusters) reset() { func (c Clusters) reset() {
for i := 0; i < len(c); i++ { for i := 0; i < len(c); i++ {
c[i].Points = Points{} c[i].Points = Points{}