https://github.com/chneau/dbscan
DBSCAN clustering algorithm implementation written in Go using generics.
https://github.com/chneau/dbscan
Last synced: 12 months ago
JSON representation
DBSCAN clustering algorithm implementation written in Go using generics.
- Host: GitHub
- URL: https://github.com/chneau/dbscan
- Owner: chneau
- License: mit
- Created: 2025-04-02T14:39:41.000Z (about 1 year ago)
- Default Branch: master
- Last Pushed: 2025-04-02T15:03:10.000Z (about 1 year ago)
- Last Synced: 2025-06-10T00:40:09.357Z (12 months ago)
- Language: Go
- Size: 3.91 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# dbscan
DBSCAN clustering algorithm implementation written in Go using generics.
## Example
```go
package main
import (
"fmt"
"math/rand"
"github.com/chneau/dbscan"
)
type Numbers int64
func (e Numbers) Coordinates() []float64 {
return []float64{float64(e)}
}
func ExampleNumbers() {
dataset := []Numbers{
// first cluster
1, 2, 3,
// second cluster
11, 12, 13,
// third cluster
21, 22, 23,
// outlier
100,
}
minDensity := 1
epsilon := 2.0
rng := rand.New(rand.NewSource(0))
clusters, err := dbscan.Cluster(dataset, minDensity, epsilon, rng)
if err != nil {
panic(err)
}
// Output: (Unordered)
// Cluster 0: Observations = [1 2 3]
// Cluster 1: Observations = [11 12 13]
// Cluster 2: Observations = [21 22 23]
// Cluster 3: Observations = [100]
for i, cluster := range clusters {
fmt.Printf("Cluster %d: Observations = %v\n", i, cluster)
}
}
type Coordinates [2]int
func (c Coordinates) Coordinates() []float64 {
return []float64{float64(c[0]), float64(c[1])}
}
func ExampleCoordinates() {
dataset := []Coordinates{
// first cluster
{1, 2}, {2, 3}, {3, 4},
// second cluster
{11, 12}, {12, 13}, {13, 14},
// third cluster
{21, 22}, {22, 23}, {23, 24},
// outlier
{100, 200},
}
minDensity := 1
epsilon := 4.0
rng := rand.New(rand.NewSource(0))
clusters, err := dbscan.Cluster(dataset, minDensity, epsilon, rng)
if err != nil {
panic(err)
}
// Output: (Unordered)
// Cluster 0: Observations = [[1 2] [2 3] [3 4]]
// Cluster 1: Observations = [[11 12] [12 13] [13 14]]
// Cluster 2: Observations = [[21 22] [22 23] [23 24]]
// Cluster 3: Observations = [[100 200]]
for i, cluster := range clusters {
fmt.Printf("Cluster %d: Observations = %v\n", i, cluster)
}
}
func main() {
ExampleNumbers()
ExampleCoordinates()
}
```