k-means clustering in Ruby
k-means clustering in Ruby. Uses NArray under the hood for fast calculations.
Jump to the examples directory to see this in action.
gem install kmeans-clustererSimple example:
…Output of simple example:
0. New York, Baltimore, Washington DC [39.63, -75.89]
1. Los Angeles, Portland, Las Vegas [38.56, -118.7]
Closest cluster to Chicago: 0
Silhouette score: 0.91The following options can be passed in to KMeansClusterer.run:
| option | default | description |
|---|---|---|
| :labels | nil | optional array of Ruby objects to collate with data array |
| :runs | 10 | number of times to run kmeans |
| :log | false | print stats after each run |
| :init | :kmpp | algorithm for picking initial cluster centroids. Accepts :kmpp, :random, or an array of k centroids |
| :scale_data | false | scales features before clustering using formula (data - mean) / std |
| :float_precision | :double | float precision to use. :double or :single |
| :max_iter | 300 | max iterations per run |
No open issues yet, or sync has not completed.