Skip to content

Instantly share code, notes, and snippets.

@dstein64
Created July 4, 2019 23:33
Show Gist options
  • Save dstein64/0e0d7f80ce6148881926b8fd6852072a to your computer and use it in GitHub Desktop.
Save dstein64/0e0d7f80ce6148881926b8fd6852072a to your computer and use it in GitHub Desktop.
import kmeans1d
x = [4.0, 4.1, 4.2, -50, 200.2, 200.4, 200.9, 80, 100, 102]
k = 4
clusters, centroids = kmeans1d.cluster(x, k)
print(clusters) # [1, 1, 1, 0, 3, 3, 3, 2, 2, 2]
print(centroids) # [-50.0, 4.1, 94.0, 200.5]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment