{"id":13444608,"url":"https://github.com/muesli/kmeans","last_synced_at":"2025-04-12T19:44:27.561Z","repository":{"id":33828471,"uuid":"134927632","full_name":"muesli/kmeans","owner":"muesli","description":"k-means clustering algorithm implementation written in Go","archived":false,"fork":false,"pushed_at":"2023-06-17T12:42:51.000Z","size":3807,"stargazers_count":466,"open_issues_count":6,"forks_count":52,"subscribers_count":8,"default_branch":"master","last_synced_at":"2025-04-03T22:09:58.909Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/muesli.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null},"funding":{"github":"muesli"}},"created_at":"2018-05-26T04:00:19.000Z","updated_at":"2025-03-28T23:18:11.000Z","dependencies_parsed_at":"2024-04-09T21:47:44.574Z","dependency_job_id":"8530cbe1-6d34-4e60-a8a5-4b2895859dc2","html_url":"https://github.com/muesli/kmeans","commit_stats":{"total_commits":74,"total_committers":6,"mean_commits":"12.333333333333334","dds":0.08108108108108103,"last_synced_commit":"06e72b51dbf15ea9e20146451e2c523389633707"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fkmeans","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fkmeans/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fkmeans/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/muesli%2Fkmeans/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/muesli","download_url":"https://codeload.github.com/muesli/kmeans/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248625479,"owners_count":21135512,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-07-31T04:00:32.152Z","updated_at":"2025-04-12T19:44:27.541Z","avatar_url":"https://github.com/muesli.png","language":"Go","funding_links":["https://github.com/sponsors/muesli"],"categories":["Cluster","Go"],"sub_categories":["Vector Database"],"readme":"# kmeans\n\n[![Latest Release](https://img.shields.io/github/release/muesli/kmeans.svg)](https://github.com/muesli/kmeans/releases)\n[![Build Status](https://github.com/muesli/kmeans/workflows/build/badge.svg)](https://github.com/muesli/kmeans/actions)\n[![Coverage Status](https://coveralls.io/repos/github/muesli/kmeans/badge.svg?branch=master)](https://coveralls.io/github/muesli/kmeans?branch=master)\n[![Go ReportCard](https://goreportcard.com/badge/muesli/kmeans)](https://goreportcard.com/report/muesli/kmeans)\n[![GoDoc](https://godoc.org/github.com/golang/gddo?status.svg)](https://pkg.go.dev/github.com/muesli/kmeans)\n\nk-means clustering algorithm implementation written in Go\n\n## What It Does\n\n[k-means clustering](https://en.wikipedia.org/wiki/K-means_clustering) partitions\na multi-dimensional data set into `k` clusters, where each data point belongs\nto the cluster with the nearest mean, serving as a prototype of the cluster.\n\n![kmeans animation](https://github.com/muesli/kmeans/blob/master/kmeans.gif)\n\n## When Should I Use It?\n\n- When you have numeric, multi-dimensional data sets\n- You don't have labels for your data\n- You know exactly how many clusters you want to partition your data into\n\n## Example\n\n```go\nimport (\n\t\"github.com/muesli/kmeans\"\n\t\"github.com/muesli/clusters\"\n)\n\n// set up a random two-dimensional data set (float64 values between 0.0 and 1.0)\nvar d clusters.Observations\nfor x := 0; x \u003c 1024; x++ {\n\td = append(d, clusters.Coordinates{\n\t\trand.Float64(),\n\t\trand.Float64(),\n\t})\n}\n\n// Partition the data points into 16 clusters\nkm := kmeans.New()\nclusters, err := km.Partition(d, 16)\n\nfor _, c := range clusters {\n\tfmt.Printf(\"Centered at x: %.2f y: %.2f\\n\", c.Center[0], c.Center[1])\n\tfmt.Printf(\"Matching data points: %+v\\n\\n\", c.Observations)\n}\n```\n\n## Complexity\n\nIf `k` (the amount of clusters) and `d` (the dimensions) are fixed, the problem\ncan be exactly solved in time O(n\u003csup\u003edk+1\u003c/sup\u003e), where `n` is the number of\nentities to be clustered.\n\nThe running time of the algorithm is O(nkdi), where `n` is the number of\n`d`-dimensional vectors, `k` the number of clusters and `i` the number of\niterations needed until convergence. On data that does have a clustering\nstructure, the number of iterations until convergence is often small, and\nresults only improve slightly after the first dozen iterations. The algorithm\nis therefore often considered to be of \"linear\" complexity in practice,\nalthough it is in the worst case superpolynomial when performed until\nconvergence.\n\n## Options\n\nYou can greatly reduce the running time by adjusting the required delta\nthreshold. With the following options the algorithm finishes when less than 5%\nof the data points shifted their cluster assignment in the last iteration:\n\n```go\nkm, err := kmeans.NewWithOptions(0.05, nil)\n```\n\nThe default setting for the delta threshold is 0.01 (1%).\n\nIf you are working with two-dimensional data sets, kmeans can generate\nbeautiful graphs (like the one above) for each iteration of the algorithm:\n\n```go\nkm, err := kmeans.NewWithOptions(0.01, plotter.SimplePlotter{})\n```\n\nCareful: this will generate PNGs in your current working directory.\n\nYou can write your own plotters by implementing the `kmeans.Plotter` interface.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuesli%2Fkmeans","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmuesli%2Fkmeans","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmuesli%2Fkmeans/lists"}